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() {
		eventSource = new(eventfakes.FakeEventSource)
		bbsClient = new(fake_bbs.FakeClient)
		bbsClient.SubscribeToEventsReturns(eventSource, nil)

		table = &fake_routing_table.FakeRoutingTable{}
		emitter = &fake_nats_emitter.FakeNATSEmitter{}
		syncEvents = syncer.Events{
			Sync: make(chan struct{}),
			Emit: make(chan struct{}),
		}
		logger = lagertest.NewTestLogger("test")

		dummyEndpoint := routing_table.Endpoint{InstanceGuid: expectedInstanceGuid, Host: expectedHost, Port: expectedContainerPort}
		dummyMessage := routing_table.RegistryMessageFor(dummyEndpoint, routing_table.Routes{Hostnames: []string{"foo.com", "bar.com"}, LogGuid: logGuid})
		dummyMessagesToEmit = routing_table.MessagesToEmit{
			RegistrationMessages: []routing_table.RegistryMessage{dummyMessage},
		}
		})

		JustBeforeEach(func() {
			var err error
			request, err = http.NewRequest("GET", server.URL, nil)
			Expect(err).NotTo(HaveOccurred())
			go func() {
				defer GinkgoRecover()
				response, _ := http.DefaultClient.Do(request)
				responseChan <- response
			}()
		})

		Context("when failing to subscribe to the event stream", func() {
			BeforeEach(func() {
				fakeBBS.SubscribeToEventsReturns(nil, models.ErrUnknownError)
			})

			It("returns an internal server error", func() {
				response := &http.Response{}
				Eventually(responseChan).Should(Receive(&response))
				Expect(response.StatusCode).To(Equal(http.StatusInternalServerError))
			})
		})

		Context("when connection is closed before subscription is complete", func() {
			var subscribe chan bool

			BeforeEach(func() {
				subscribe = make(chan bool)
				fakeBBS.SubscribeToEventsStub = func() (events.EventSource, error) {