예제 #1
0
파일: common.go 프로젝트: anovikov1984/go
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
			}
		}
}
예제 #2
0
파일: common.go 프로젝트: anovikov1984/go
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
			}
		}
}
예제 #3
0
파일: common.go 프로젝트: anovikov1984/go
	}

	return strings.Join(channelsArray[:length], ","), strings.Join(channelsArray[length:], ",")
}

func RandomChannel() string {
	channel, _ := GenerateTwoRandomChannelStrings(1)
	return channel
}

func RandomChannels(length int) string {
	channel, _ := GenerateTwoRandomChannelStrings(length)
	return channel
}

var pubnubMatcher cassette.Matcher = utils.NewPubnubMatcher([]string{})

type VCRTransportStub int

const (
	vcrStubSubscribe VCRTransportStub = 1 << iota
	vcrStubNonSubscribe
)

var vcrMu sync.Mutex
var defaultFieldsToSkip = []string{"pnsdk"}

func NewVCRNonSubscribe(name string, skipFields []string) (
	func(), func(int)) {

	vcrMu.Lock()