Ejemplo n.º 1
0
				eventSource.NextStub = func() (routing_api.Event, error) {
					received <- struct{}{}
					return routing_api.Event{}, errors.New("beep boop im a robot")
				}

				tokenFetcher.FetchTokenReturns(token, nil)
				fetcher.StartEventCycle()

				<-received

				Expect(sink.Records()).ToNot(BeNil())
				Expect(sink.Records()[1].Message).To(Equal("beep boop im a robot"))
				Eventually(func() int {
					return tokenFetcher.FetchTokenCallCount()
				}, 1).Should(BeNumerically(">=", 2))
				Expect(eventSource.CloseCallCount()).To(Equal(1))
			})
		})

		Context("and the event source fails to subscribe", func() {
			It("logs the error and tries again", func() {
				subscribed := make(chan struct{})
				client.SubscribeToEventsStub = func() (routing_api.EventSource, error) {
					subscribed <- struct{}{}
					err := errors.New("i failed to subscribe")
					return &fake_routing_api.FakeEventSource{}, err
				}

				tokenFetcher.FetchTokenReturns(token, nil)
				fetcher.StartEventCycle()