Example #1
0
func NewVCRBoth(name string, skipFields []string) (
	func(), func(int)) {

	vcrMu.Lock()

	skipFields = append(skipFields, defaultFieldsToSkip...)
	s, _ := recorder.New(fmt.Sprintf("%s_%s", name, "Subscribe"))
	s.UseMatcher(utils.NewPubnubSubscribeMatcher(skipFields))

	ns, _ := recorder.New(fmt.Sprintf("%s_%s", name, "NonSubscribe"))
	ns.UseMatcher(utils.NewPubnubMatcher(skipFields))

	sDial := genVcrDial()

	s.Transport.Dial = sDial

	messaging.SetSubscribeTransport(s.Transport)
	messaging.SetNonSubscribeTransport(ns.Transport)

	return func() {
			s.Stop()
			ns.Stop()

			messaging.SetSubscribeTransport(nil)
			messaging.SetNonSubscribeTransport(nil)
			vcrMu.Unlock()
		}, func(seconds int) {
			mode := recorder.ModeRecording
			if ns.Mode() == mode && s.Mode() == mode {
				time.Sleep(time.Duration(seconds) * time.Second)
			} else {
				// do not sleep
			}
		}
}
Example #2
0
func NewVCRSubscribe(name string, skipFields []string) func() {
	vcrMu.Lock()

	skipFields = append(skipFields, defaultFieldsToSkip...)
	s, _ := recorder.New(fmt.Sprintf("%s_%s", name, "Subscribe"))
	sMatcher := utils.NewPubnubSubscribeMatcher(skipFields)
	s.UseMatcher(sMatcher)
	messaging.SetSubscribeTransport(s.Transport)

	sDial := genVcrDial()

	s.Transport.Dial = sDial

	return func() {
		s.Stop()

		messaging.SetSubscribeTransport(nil)
		vcrMu.Unlock()
	}
}
Example #3
0
func NewVCRNonSubscribe(name string, skipFields []string) (
	func(), func(int)) {

	vcrMu.Lock()
	skipFields = append(skipFields, defaultFieldsToSkip...)
	ns, _ := recorder.New(fmt.Sprintf("%s_%s", name, "NonSubscribe"))
	nsMatcher := utils.NewPubnubMatcher(skipFields)
	ns.UseMatcher(nsMatcher)
	messaging.SetNonSubscribeTransport(ns.Transport)

	return func() {
			ns.Stop()

			messaging.SetNonSubscribeTransport(nil)
			vcrMu.Unlock()
		}, func(seconds int) {
			if ns.Mode() == recorder.ModeRecording {
				time.Sleep(time.Duration(seconds) * time.Second)
			} else {
				// do not sleep
			}
		}
}