return nil, errors.New("broken")
				}
			})

			It("returns an internal server error", func() {
				Eventually(fakeBBS.SubscribeToEventsCallCount).Should(Equal(1))
				http.DefaultTransport.(*http.Transport).CancelRequest(request)

				// should not timeout
				server.Close()
				Eventually(responseChan).Should(Receive())
			})
		})

		Context("when successfully subscribing to the event stream", func() {
			var eventSource *eventfakes.FakeEventSource
			var eventChannel chan models.Event

			BeforeEach(func() {
				eventChannel = make(chan models.Event, 2)
				eventSource = new(eventfakes.FakeEventSource)
				eventSource.NextStub = func() (models.Event, error) {
					select {
					case event := <-eventChannel:
						return event, nil
					case <-time.After(time.Second):
					}
					return nil, errors.New("timeout waiting for events")
				}
				fakeBBS.SubscribeToEventsReturns(eventSource, nil)
			})
	)

	var (
		eventSource *eventfakes.FakeEventSource
		bbsClient   *fake_bbs.FakeClient
		table       *fake_routing_table.FakeRoutingTable
		emitter     *fake_nats_emitter.FakeNATSEmitter
		syncEvents  syncer.Events

		clock          *fakeclock.FakeClock
		watcherProcess *watcher.Watcher
		process        ifrit.Process

		expectedRoutes     []string
		expectedRoutingKey routing_table.RoutingKey
		expectedCFRoute    cfroutes.CFRoute

		expectedAdditionalRoutes     []string
		expectedAdditionalRoutingKey routing_table.RoutingKey
		expectedAdditionalCFRoute    cfroutes.CFRoute

		dummyMessagesToEmit routing_table.MessagesToEmit
		fakeMetricSender    *fake_metrics_sender.FakeMetricSender

		logger *lagertest.TestLogger

		nextErr   atomic.Value
		nextEvent atomic.Value
	)

	BeforeEach(func() {
Esempio n. 3
0
)

type EventHolder struct {
	event models.Event
}

var nilEventHolder = EventHolder{}

var _ = Describe("Watcher", func() {

	var (
		eventSource   *eventfakes.FakeEventSource
		bbsClient     *fake_bbs.FakeClient
		ccClient      *fakes.FakeCcClient
		watcherRunner *watcher.Watcher
		process       ifrit.Process

		logger *lagertest.TestLogger

		nextErr   atomic.Value
		nextEvent atomic.Value
	)

	BeforeEach(func() {
		eventSource = new(eventfakes.FakeEventSource)
		bbsClient = new(fake_bbs.FakeClient)
		bbsClient.SubscribeToEventsReturns(eventSource, nil)

		logger = lagertest.NewTestLogger("test")
		ccClient = new(fakes.FakeCcClient)

		var err error