Пример #1
0
	Context("at initialization", func() {
		It("connects to the store", func() {
			elector.NewElector("name", fakeStore, 1*time.Millisecond, logger)
			Expect(fakeStore.DidConnect).To(BeTrue())
		})

		Context("when store connection fails", func() {
			BeforeEach(func() {
				fakeStore.ConnectErr = errors.New("connection error")
			})

			It("logs an error", func() {
				go elector.NewElector("name", fakeStore, 100*time.Millisecond, logger)

				Eventually(func() int { return len(testingSink.Records()) }).Should(BeNumerically(">=", 1))
				var messages []string
				for _, record := range testingSink.Records() {
					messages = append(messages, record.Message)
				}

				Expect(messages).To(ContainElement("Elector: Unable to connect to store: 'connection error'"))
			})

			It("reconnects on an interval", func() {
				go elector.NewElector("name", fakeStore, 10*time.Millisecond, logger)

				Eventually(func() int { return len(testingSink.Records()) }).Should(BeNumerically(">=", 2))
			})
		})
	})
Пример #2
0
		It("can handle an empty reply in the subject", func() {
			component.Varz.Type = "TestType"
			component.Logger = logger

			err := component.Start()
			Expect(err).ToNot(HaveOccurred())

			err = component.Register(mbusClient)
			Expect(err).ToNot(HaveOccurred())

			err = mbusClient.PublishRequest("vcap.component.discover", "", []byte(""))
			Expect(err).ToNot(HaveOccurred())

			Eventually(func() bool {
				found := false
				for _, r := range sink.Records() {
					if strings.Contains(r.Message, "Received message with empty reply on subject") {
						found = true
					}
				}
				return found
			}).Should(BeTrue())

			err = mbusClient.PublishRequest("vcap.component.discover", "reply", []byte("hi"))
			Expect(err).ToNot(HaveOccurred())
		})
	})
})

func startComponent(component *VcapComponent) {
	err := component.Start()
Пример #3
0
				Eventually(client.RoutesCallCount, "2s").Should(Equal(1))
				clock.Increment(cfg.PruneStaleDropletsInterval + 100*time.Millisecond)
				Eventually(client.RoutesCallCount, "2s").Should(Equal(2))
			})
		})

		Context("when token fetcher returns error", func() {
			BeforeEach(func() {
				tokenFetcher.FetchTokenReturns(nil, errors.New("Unauthorized"))
			})

			It("logs the error", func() {
				currentTokenFetchErrors := sender.GetCounter(TokenFetchErrors)

				Eventually(func() int {
					return len(sink.Records())
				}).Should(BeNumerically(">=", 1))

				Expect(sink.Records()).ToNot(BeNil())
				Expect(sink.Records()[0].Message).To(Equal("Unauthorized"))

				Eventually(tokenFetcher.FetchTokenCallCount).Should(BeNumerically(">=", 2))
				Expect(client.SubscribeToEventsCallCount()).Should(Equal(0))
				Expect(client.RoutesCallCount()).Should(Equal(0))

				Eventually(func() uint64 {
					return sender.GetCounter(TokenFetchErrors)
				}).Should(BeNumerically(">", currentTokenFetchErrors))
			})
		})
Пример #4
0
				received <- struct{}{}
				return []db.Route{}, nil
			}

			fetcher.StartFetchCycle()

			Eventually(received).Should(Receive())
			Eventually(received).Should(Receive())
		})

		It("logs the error", func() {
			tokenFetcher.FetchTokenReturns(nil, errors.New("Unauthorized"))
			fetcher.StartFetchCycle()

			Eventually(func() int {
				return len(sink.Records())
			}).Should(BeNumerically(">=", 1))

			Expect(sink.Records()).ToNot(BeNil())
			Expect(sink.Records()[0].Message).To(Equal("Unauthorized"))
		})
	})

	Describe(".StartEventCycle", func() {
		Context("when fetching the auth token fails", func() {
			It("logs the failure and tries again", func() {
				received := make(chan struct{})

				tokenFetcher.FetchTokenStub = func() (*token_fetcher.Token, error) {
					received <- struct{}{}
					return nil, errors.New("failed to get the token")