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)
			})

			It("emits events from the stream to the connection", func(done Done) {
				response := &http.Response{}
				Eventually(responseChan).Should(Receive(&response))
				reader := sse.NewReadCloser(response.Body)

				desiredLRP := &models.DesiredLRP{
					ProcessGuid: "some-guid",
					Domain:      "some-domain",
					RootFs:      "some-rootfs",
예제 #2
0
		nextEvent.Store(nilEventHolder)

		eventSource.CloseStub = func() error {
			nextErr.Store(errors.New("closed"))
			return nil
		}

		eventSource.NextStub = func() (models.Event, error) {
			time.Sleep(10 * time.Millisecond)
			if eventHolder := nextEvent.Load(); eventHolder != nil || eventHolder != nilEventHolder {
				nextEvent.Store(nilEventHolder)

				eh := eventHolder.(EventHolder)
				if eh.event != nil {
					return eh.event, nil
				}
			}

			if err := nextErr.Load(); err != nil {
				return nil, err.(error)
			}

			return nil, nil
		}
	})

	JustBeforeEach(func() {
		process = ifrit.Invoke(watcherProcess)
	})

	AfterEach(func() {
예제 #3
0
		nextEvent.Store(nilEventHolder)

		eventSource.CloseStub = func() error {
			nextErr.Store(errors.New("closed"))
			return nil
		}

		eventSource.NextStub = func() (models.Event, error) {
			time.Sleep(10 * time.Millisecond)
			if eventHolder := nextEvent.Load(); eventHolder != nilEventHolder {
				nextEvent.Store(nilEventHolder)

				eh := eventHolder.(EventHolder)
				if eh.event != nil {
					return eh.event, nil
				}
			}

			if err := nextErr.Load(); err != nil {
				return nil, err.(error)
			}

			return nil, nil
		}
	})

	JustBeforeEach(func() {
		process = ifrit.Invoke(watcherRunner)
	})

	AfterEach(func() {