예제 #1
0
파일: main.go 프로젝트: emc-xchallenge/bbs
func closeHub(logger lager.Logger, hub events.Hub) ifrit.Runner {
	return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
		logger.Info("starting")
		defer logger.Info("finished")

		close(ready)
		logger.Info("started")

		<-signals
		logger.Info("shutting-down")
		hub.Close()

		return nil
	})
}
예제 #2
0
파일: main.go 프로젝트: timani/bbs
func hubMaintainer(logger lager.Logger, desiredHub, actualHub events.Hub) ifrit.RunFunc {
	return func(signals <-chan os.Signal, ready chan<- struct{}) error {
		logger := logger.Session("hub-maintainer")
		close(ready)
		logger.Info("started")
		defer logger.Info("finished")

		<-signals
		err := desiredHub.Close()
		if err != nil {
			logger.Error("error-closing-desired-hub", err)
		}
		err = actualHub.Close()
		if err != nil {
			logger.Error("error-closing-actual-hub", err)
		}
		return nil
	}
}
예제 #3
0
		handler *handlers.EventHandler

		server *httptest.Server
	)

	BeforeEach(func() {
		hub = events.NewHub()

		logger = lager.NewLogger("test")
		logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.DEBUG))

		handler = handlers.NewEventHandler(logger, hub)
	})

	AfterEach(func() {
		hub.Close()

		if server != nil {
			server.Close()
		}
	})

	Describe("Subscribe", func() {
		var (
			response        *http.Response
			eventStreamDone chan struct{}
		)

		BeforeEach(func() {
			eventStreamDone = make(chan struct{})
			server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
예제 #4
0
파일: hub_test.go 프로젝트: Gerg/bbs
					Expect(err).NotTo(HaveOccurred())

					// emit event so hub sees closed source and drops subscription
					hub.Emit(eventfakes.FakeEvent{})
				})

				It("calls the callback with a zero count", func() {
					Eventually(counts).Should(Receive(BeZero()))
				})
			})

			Context("when the hub is closed", func() {
				BeforeEach(func() {
					Eventually(counts).Should(Receive())

					err := hub.Close()
					Expect(err).NotTo(HaveOccurred())
				})

				It("calls the callback with a zero count", func() {
					Eventually(counts).Should(Receive(BeZero()))
				})
			})
		})
	})

	It("fans-out events emitted to it to all subscribers", func() {
		source1, err := hub.Subscribe()
		Expect(err).NotTo(HaveOccurred())
		source2, err := hub.Subscribe()
		Expect(err).NotTo(HaveOccurred())
예제 #5
0
		handler         *handlers.EventHandler
		eventStreamDone chan struct{}
		server          *httptest.Server
	)

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		desiredHub = events.NewHub()
		actualHub = events.NewHub()
		handler = handlers.NewEventHandler(logger, desiredHub, actualHub)

		eventStreamDone = make(chan struct{})
	})

	AfterEach(func() {
		desiredHub.Close()
		actualHub.Close()
		server.Close()
	})

	var ItStreamsEventsFromHub = func(hubRef *events.Hub) {
		Describe("Streaming Events", func() {
			var hub events.Hub
			var response *http.Response

			BeforeEach(func() {
				hub = *hubRef
			})

			JustBeforeEach(func() {
				var err error