Пример #1
0
	AfterEach(func() {
		ginkgomon.Kill(heartbeaterProcess)
	})

	Context("when the router greeting is successful", func() {
		var expectedRegisterInterval = time.Second
		var greetingMsg = natbeat.GreetingMessage{
			Id:               "some-router-id",
			Hosts:            []string{"1.2.3.4"},
			RegisterInterval: expectedRegisterInterval,
		}

		BeforeEach(func() {
			fakeNatsClient.Subscribe("router.greet", func(msg *nats.Msg) {
				fakeNatsClient.Publish(msg.Reply, toJson(greetingMsg))
			})
		})

		Context("when no new router.start messages occur", func() {
			It("emits a registration on the the 'router.register' topic at the interval specified in the greeting", func() {
				testHeartbeatsOnTime(registrations, expectedRegistryMsg, expectedRegisterInterval)
			})
		})

		Context("when a router.start message occurs with a different register interval", func() {
			var newExpectedRegisterInterval = expectedRegisterInterval * 2
			var newGreetingMsg = natbeat.GreetingMessage{
				Id:               "some-router-id",
				Hosts:            []string{"1.2.3.4"},
				RegisterInterval: newExpectedRegisterInterval,
Пример #2
0
				It("should only greet the router once", func() {
					Eventually(greetings).Should(Receive())
					Consistently(greetings, 1).ShouldNot(Receive())
				})
			})
		})

		Context("when the router does not emit a router.start", func() {
			It("should keep greeting the router until it gets an interval", func() {
				//get the first greeting
				Eventually(greetings, 2).Should(Receive())

				//get the second greeting, and respond
				var msg *nats.Msg
				Eventually(greetings, 2).Should(Receive(&msg))
				go natsClient.Publish(msg.Reply, []byte(`{"minimumRegisterIntervalInSeconds":1, "pruneThresholdInSeconds": 3}`))

				//should no longer be greeting the router
				Consistently(greetings).ShouldNot(Receive())
			})
		})

		Context("after getting the first interval, when a second interval arrives", func() {
			JustBeforeEach(func() {
				routerStartMessages <- &nats.Msg{
					Data: []byte(`{"minimumRegisterIntervalInSeconds":1, "pruneThresholdInSeconds": 3}`),
				}
			})

			It("should modify its update rate", func() {
				routerStartMessages <- &nats.Msg{