예제 #1
0
		AfterEach(func() {
			process.Signal(os.Interrupt)
			Eventually(process.Wait(), 5*time.Second).Should(Receive())
		})

		It("subscribes for events", func() {
			Eventually(client.SubscribeToEventsWithMaxRetriesCallCount).Should(Equal(1))
		})

		Context("on specified interval", func() {
			BeforeEach(func() {
				client.SubscribeToEventsWithMaxRetriesReturns(&fake_routing_api.FakeEventSource{}, errors.New("not used"))
			})

			It("fetches routes", func() {
				clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
				Eventually(client.RoutesCallCount, 2*time.Second, 50*time.Millisecond).Should(Equal(1))
				clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
				Eventually(client.RoutesCallCount, 2*time.Second, 50*time.Millisecond).Should(Equal(2))
			})

			It("uses cache when fetching token from uaa", func() {
				clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
				Eventually(client.RoutesCallCount, 2*time.Second, 50*time.Millisecond).Should(Equal(1))
				Expect(uaaClient.FetchTokenArgsForCall(0)).To(Equal(false))
			})
		})

		Context("when token fetcher returns error", func() {
			BeforeEach(func() {
				uaaClient.FetchTokenReturns(nil, errors.New("Unauthorized"))
			It("should have fake driver in registry map", func() {
				drivers := registry.Drivers()
				Expect(len(drivers)).To(Equal(1))
				Expect(fakeDriverFactory.DriverCallCount()).To(Equal(1))
				Expect(fakeDriver.ActivateCallCount()).To(Equal(1))
			})

			Context("when drivers are added", func() {
				BeforeEach(func() {
					err := voldriver.WriteDriverSpec(logger, defaultPluginsDirectory, "anotherfakedriver", "spec", []byte("http://0.0.0.0:8080"))
					Expect(err).NotTo(HaveOccurred())
				})

				It("should find them!", func() {
					fakeClock.Increment(scanInterval * 2)
					Eventually(registry.Drivers).Should(HaveLen(2))
					Expect(fakeDriverFactory.DriverCallCount()).To(Equal(3))
					Expect(fakeDriver.ActivateCallCount()).To(Equal(3))
				})
			})
			Context("when drivers are not responding", func() {
				BeforeEach(func() {
					fakeDriver.ActivateReturns(voldriver.ActivateResponse{
						Err: "some err",
					})
				})

				It("should find no drivers", func() {
					fakeClock.Increment(scanInterval * 2)
					Eventually(registry.Drivers).Should(HaveLen(0))
예제 #3
0
		}).Should(Equal(numSessions))
	}

	Context("When consul is running", func() {
		Context("an error occurs while acquiring the lock", func() {
			BeforeEach(func() {
				lockKey = ""
			})

			It("continues to retry", func() {
				lockProcess = ifrit.Background(lockRunner)
				shouldEventuallyHaveNumSessions(1)
				Consistently(lockProcess.Ready()).ShouldNot(BeClosed())
				Consistently(lockProcess.Wait()).ShouldNot(Receive())

				clock.Increment(retryInterval)
				Eventually(logger).Should(Say("acquire-lock-failed"))
				Eventually(logger).Should(Say("retrying-acquiring-lock"))
				Expect(sender.GetValue(lockHeldMetricName).Value).To(Equal(float64(0)))
			})
		})

		Context("and the lock is available", func() {
			It("acquires the lock", func() {
				lockProcess = ifrit.Background(lockRunner)
				Eventually(lockProcess.Ready()).Should(BeClosed())
				Expect(sender.GetValue(lockUptimeMetricName).Value).Should(Equal(float64(0)))
				Expect(getLockValue()).To(Equal(lockValue))
				Expect(sender.GetValue(lockHeldMetricName).Value).To(Equal(float64(1)))
			})
}

var verifyFetchWithRetries = func(client uaa_go_client.Client, server *ghttp.Server, numRetries int, expectedErrorMsg string) {
	var err error
	wg := sync.WaitGroup{}
	wg.Add(1)
	go func(wg *sync.WaitGroup) {
		defer GinkgoRecover()
		defer wg.Done()
		_, err = client.FetchToken(forceUpdate)
		Expect(err).To(HaveOccurred())
	}(&wg)

	for i := 0; i < numRetries; i++ {
		Eventually(server.ReceivedRequests, 7*time.Second, 1*time.Second).Should(HaveLen(i + 1))
		clock.Increment(DefaultRetryInterval + 10*time.Second)
	}

	wg.Wait()

	Expect(err.Error()).To(ContainSubstring(expectedErrorMsg))
}

var getRegisterOauthClientHandlerFunc = func(status int, token *schema.Token, oauthClient *schema.OauthClient) http.HandlerFunc {
	oauthClientString, err := json.Marshal(oauthClient)
	var responseBody string
	if status == http.StatusOK {
		responseBody = string(oauthClientString)
	} else {
		responseBody = ""
	}
예제 #5
0
		BeforeEach(func() {
			schedDone = make(chan struct{})
		})

		JustBeforeEach(func() {
			go func(sched *scheduler.Scheduler, c chan struct{}) {
				defer GinkgoRecover()
				Expect(sched.Run).NotTo(Panic())
				close(c)
			}(sched, schedDone)
			clk.WaitForWatcherAndIncrement(csSleep)
		})

		AfterEach(func() {
			Expect(sched.Stop()).To(Succeed())
			clk.Increment(csSleep)
			Eventually(schedDone).Should(BeClosed())
		})

		Context("when there are no tasks", func() {
			It("should not call the task selector", func() {
				Expect(taskSelector.SelectTaskCallCount()).To(Equal(0))
			})
		})

		Context("when there are tasks", func() {
			var (
				taskA, taskB *fakes.FakeTask
			)

			BeforeEach(func() {