Пример #1
0
func constructStopper(database db.DB) ifrit.Runner {
	return ifrit.RunFunc(func(signals <-chan os.Signal, ready chan<- struct{}) error {
		close(ready)
		select {
		case <-signals:
			database.CancelWatches()
		}

		return nil
	})
}
Пример #2
0
			})

			Describe("WatchRouteChanges with http events", func() {
				It("does return an error when canceled", func() {
					_, errors, cancel := etcd.WatchRouteChanges(db.HTTP_ROUTE_BASE_KEY)
					cancel()
					Consistently(errors).ShouldNot(Receive())
					Eventually(errors).Should(BeClosed())
				})

				Context("Cancel Watches", func() {
					It("cancels any in-flight watches", func() {
						results, err, _ := etcd.WatchRouteChanges(db.HTTP_ROUTE_BASE_KEY)
						results2, err2, _ := etcd.WatchRouteChanges(db.HTTP_ROUTE_BASE_KEY)

						etcd.CancelWatches()

						Eventually(err).Should(BeClosed())
						Eventually(err2).Should(BeClosed())
						Eventually(results).Should(BeClosed())
						Eventually(results2).Should(BeClosed())
					})
				})

				Context("with wrong event type", func() {
					BeforeEach(func() {
						fakeresp := &client.Response{Action: "some-action"}
						fakeWatcher := &fakes.FakeWatcher{}
						fakeWatcher.NextReturns(fakeresp, nil)
						fakeKeysAPI.WatcherReturns(fakeWatcher)
					})