コード例 #1
0
ファイル: reader_test.go プロジェクト: myshkin5/netspel
		}
		port++

		go func() {
			defer GinkgoRecover()
			err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), http.HandlerFunc(handle))
			Expect(err).NotTo(HaveOccurred())
		}()

		events = []*vitosse.Event{}

		time.Sleep(50 * time.Millisecond)

		config = jsonstruct.New()
		config.SetString(sse.RemoteWriterAddr, "localhost")
		config.SetInt(sse.Port, port)

		reader = sse.Reader{}
	})

	It("connects to a writer via HTTP and reads SSE messages", func() {
		event := &vitosse.Event{
			ID:   "event-id",
			Name: "event-name",
			Data: make([]byte, 100),
		}
		events = append(events, event)
		events = append(events, event)

		err := reader.Init(config)
		Expect(err).NotTo(HaveOccurred())
コード例 #2
0
ファイル: scheme_test.go プロジェクト: myshkin5/netspel
	emptyReport := streaming.Report{
		MessageCount: 0,
		ByteCount:    0,
		ErrorCount:   0,
	}
	singleMessageReport := streaming.Report{
		MessageCount: 1,
		ByteCount:    1024,
		ErrorCount:   0,
	}

	Context("with a 5-messages-per-second configuration", func() {
		BeforeEach(func() {
			// one message per 100ms
			config.SetInt(streaming.MessagesPerSecond, 10)
			// will alternate reports of 0 and 1 messages per report
			config.SetDuration(streaming.ReportCycle, 80*time.Millisecond)

			err := scheme.Init(config)
			Expect(err).NotTo(HaveOccurred())
		})

		It("sets up the reporter properly", func() {
			Expect(reporter.expectedMessagesPerSecond).To(Equal(10))
			Expect(reporter.reportCycle).To(Equal(80 * time.Millisecond))
		})

		It("writes messages at the rate specified", func() {
			go scheme.RunWriter(writer)
コード例 #3
0
ファイル: setters_test.go プロジェクト: myshkin5/jsonstruct
			Expect(value).To(Equal("hi"))
		})
	})

	Describe("SetInt()", func() {
		It("overrides existing values", func() {
			err := json.Unmarshal([]byte(`{
				"this": "that",
				"parent": {
					"child": 98765
				}
			}`), &values)

			Expect(err).NotTo(HaveOccurred())

			Expect(values.SetInt(".this", 1000000)).To(Succeed())

			value, ok := values.Int(".this")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal(1000000))

			Expect(values.SetInt(".parent.child", 12345)).To(Succeed())

			value, ok = values.Int(".parent.child")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal(12345))
		})
	})

	Describe("SetDuration()", func() {
		It("sets a duration value as a string", func() {
コード例 #4
0
ファイル: scheme_test.go プロジェクト: myshkin5/netspel
)

var _ = Describe("Scheme", func() {
	var (
		writer *mocks.MockWriter
		reader *mocks.MockReader
		scheme *simple.Scheme
		config jsonstruct.JSONStruct
	)

	BeforeEach(func() {
		writer = mocks.NewMockWriter()
		reader = mocks.NewMockReader()
		scheme = &simple.Scheme{}
		config = jsonstruct.New()
		config.SetInt(simple.BytesPerMessage, 1000)
		config.SetInt(simple.MessagesPerRun, 100)
		config.SetString(simple.WaitForLastMessage, "100ms")
	})

	Context("with a short wait time", func() {
		JustBeforeEach(func() {
			config.SetString(simple.WaitForLastMessage, "100ms")
			err := scheme.Init(config)
			Expect(err).NotTo(HaveOccurred())
		})

		It("writes messages to a writer", func() {
			wg := sync.WaitGroup{}
			wg.Add(1)
			go func() {