func (s *RouterSuite) TestVarz(c *C) { app := test.NewGreetApp([]route.Uri{"count.vcap.me"}, s.Config.Port, s.mbusClient, map[string]string{"framework": "rails"}) app.Listen() c.Assert(s.waitAppRegistered(app, time.Millisecond*500), Equals, true) // Send seed request sendRequests(c, "count.vcap.me", s.Config.Port, 1) vA := s.readVarz() // Send requests sendRequests(c, "count.vcap.me", s.Config.Port, 100) vB := s.readVarz() // Verify varz update RequestsA := int(f(vA, "requests").(float64)) RequestsB := int(f(vB, "requests").(float64)) allRequests := RequestsB - RequestsA c.Check(allRequests, Equals, 100) Responses2xxA := int(f(vA, "responses_2xx").(float64)) Responses2xxB := int(f(vB, "responses_2xx").(float64)) allResponses2xx := Responses2xxB - Responses2xxA c.Check(allResponses2xx, Equals, 100) app.Unregister() }
func (s *RouterSuite) TestVarz(c *C) { app := test.NewGreetApp([]route.Uri{"count.vcap.me"}, s.Config.Port, s.mbusClient, map[string]string{"framework": "rails"}) app.Listen() additionalRequests := 100 go app.RegisterRepeatedly(100 * time.Millisecond) c.Assert(s.waitAppRegistered(app, time.Millisecond*500), Equals, true) // Send seed request sendRequests(c, "count.vcap.me", s.Config.Port, 1) initial_varz := s.readVarz() // Send requests sendRequests(c, "count.vcap.me", s.Config.Port, additionalRequests) updated_varz := s.readVarz() // Verify varz update initialRequestCount := fetchRecursively(initial_varz, "requests").(float64) updatedRequestCount := fetchRecursively(updated_varz, "requests").(float64) requestCount := int(updatedRequestCount - initialRequestCount) c.Check(requestCount, Equals, additionalRequests) initialResponse2xxCount := fetchRecursively(initial_varz, "responses_2xx").(float64) updatedResponse2xxCount := fetchRecursively(updated_varz, "responses_2xx").(float64) response2xxCount := int(updatedResponse2xxCount - initialResponse2xxCount) c.Check(response2xxCount, Equals, additionalRequests) app.Unregister() }
func (s *RouterSuite) TestRegistryLastUpdatedVarz(c *C) { app1 := test.NewGreetApp([]route.Uri{"test1.vcap.me"}, s.Config.Port, s.mbusClient, nil) app1.Listen() c.Assert(s.waitAppRegistered(app1, time.Second*1), Equals, true) time.Sleep(2 * time.Second) initialUpdateTime := fetchRecursively(s.readVarz(), "ms_since_last_registry_update").(float64) // initialUpdateTime should be roughly 2 seconds. app2 := test.NewGreetApp([]route.Uri{"test2.vcap.me"}, s.Config.Port, s.mbusClient, nil) app2.Listen() c.Assert(s.waitAppRegistered(app2, time.Second*1), Equals, true) // updateTime should be roughly 0 seconds updateTime := fetchRecursively(s.readVarz(), "ms_since_last_registry_update").(float64) c.Assert(updateTime < initialUpdateTime, Equals, true) }
func (s *IntegrationSuite) TestNatsConnectivity(c *C) { natsPort := nextAvailPort() cmd := mbus.StartNats(int(natsPort)) proxyPort := nextAvailPort() statusPort := nextAvailPort() s.Config = SpecConfig(natsPort, statusPort, proxyPort) s.Config.PruneStaleDropletsInterval = 5 * time.Second s.router = NewRouter(s.Config) go s.router.Run() natsConnected := make(chan bool, 1) go func() { for { if s.router.mbusClient.Publish("Ping", []byte("data")) == nil { break } time.Sleep(500 * time.Millisecond) } natsConnected <- true }() <-natsConnected s.mbusClient = s.router.mbusClient heartbeatInterval := 1 * time.Second staleThreshold := 5 * time.Second staleCheckInterval := s.router.registry.pruneStaleDropletsInterval s.router.registry.dropletStaleThreshold = staleThreshold app := test.NewGreetApp([]string{"test.nats.dying.vcap.me"}, proxyPort, s.mbusClient, nil) app.Listen() c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true) go func() { tick := time.Tick(heartbeatInterval) for { select { case <-tick: app.Register() } } }() app.VerifyAppStatus(200, c) mbus.StopNats(cmd) time.Sleep(staleCheckInterval + staleThreshold + 1*time.Second) app.VerifyAppStatus(200, c) }
func (s *RouterSuite) TestRegisterUnregister(c *C) { app := test.NewGreetApp([]route.Uri{"test.vcap.me"}, s.Config.Port, s.mbusClient, nil) app.Listen() c.Assert(s.waitAppRegistered(app, time.Second*5), Equals, true) app.VerifyAppStatus(200, c) app.Unregister() c.Assert(s.waitAppUnregistered(app, time.Second*5), Equals, true) app.VerifyAppStatus(404, c) }
func (s *RouterSuite) TestRegistryLastUpdatedVarz(c *C) { initialUpdateTime := f(s.readVarz(), "ms_since_last_registry_update").(float64) app1 := test.NewGreetApp([]route.Uri{"test1.vcap.me"}, s.Config.Port, s.mbusClient, nil) app1.Listen() c.Assert(s.waitAppRegistered(app1, time.Second*5), Equals, true) // varz time should be different updateTime := f(s.readVarz(), "ms_since_last_registry_update").(float64) c.Assert(updateTime < initialUpdateTime, Equals, true) }
It("has Nats connectivity", func() { localIP, err := localip.LocalIP() Expect(err).ToNot(HaveOccurred()) statusPort := test_util.NextAvailPort() proxyPort := test_util.NextAvailPort() cfgFile := filepath.Join(tmpdir, "config.yml") config := createConfig(cfgFile, statusPort, proxyPort) gorouterSession = startGorouterSession(cfgFile) mbusClient, err := newMessageBus(config) zombieApp := test.NewGreetApp([]route.Uri{"zombie.vcap.me"}, proxyPort, mbusClient, nil) zombieApp.Listen() runningApp := test.NewGreetApp([]route.Uri{"innocent.bystander.vcap.me"}, proxyPort, mbusClient, nil) runningApp.Listen() routesUri := fmt.Sprintf("http://%s:%s@%s:%d/routes", config.Status.User, config.Status.Pass, localIP, statusPort) Eventually(func() bool { return appRegistered(routesUri, zombieApp) }).Should(BeTrue()) Eventually(func() bool { return appRegistered(routesUri, runningApp) }).Should(BeTrue()) heartbeatInterval := 200 * time.Millisecond zombieTicker := time.NewTicker(heartbeatInterval) runningTicker := time.NewTicker(heartbeatInterval) go func() {
}).Should(BeTrue()) app.VerifyAppStatus(200) app.Unregister() Eventually(func() bool { return appUnregistered(registry, app) }).Should(BeTrue()) app.VerifyAppStatus(404) } Describe("app with no route service", func() { BeforeEach(func() { app = test.NewGreetApp([]route.Uri{"test.vcap.me"}, config.Port, mbusClient, nil) }) It("registers and unregisters", func() { assertRegisterUnregister() }) }) Describe("app with an http route service", func() { BeforeEach(func() { app = test.NewRouteServiceApp([]route.Uri{"test.vcap.me"}, config.Port, mbusClient, "http://my-insecure-service.me") }) It("does not register", func() { app.Listen()
func (s *IntegrationSuite) TestNatsConnectivity(c *C) { proxyPort := nextAvailPort() statusPort := nextAvailPort() s.Config = SpecConfig(s.natsPort, statusPort, proxyPort) // ensure the threshold is longer than the interval that we check, // because we set the route's timestamp to time.Now() on the interval // as part of pausing s.Config.PruneStaleDropletsInterval = 1 * time.Second s.Config.DropletStaleThreshold = 2 * s.Config.PruneStaleDropletsInterval log.SetupLoggerFromConfig(s.Config) s.router = NewRouter(s.Config) s.router.Run() s.mbusClient = s.router.mbusClient staleCheckInterval := s.Config.PruneStaleDropletsInterval staleThreshold := s.Config.DropletStaleThreshold s.Config.DropletStaleThreshold = staleThreshold zombieApp := test.NewGreetApp([]route.Uri{"zombie.vcap.me"}, proxyPort, s.mbusClient, nil) zombieApp.Listen() runningApp := test.NewGreetApp([]route.Uri{"innocent.bystander.vcap.me"}, proxyPort, s.mbusClient, nil) runningApp.Listen() c.Assert(s.waitAppRegistered(zombieApp, 2*time.Second), Equals, true) c.Assert(s.waitAppRegistered(runningApp, 2*time.Second), Equals, true) heartbeatInterval := 200 * time.Millisecond zombieTicker := time.NewTicker(heartbeatInterval) runningTicker := time.NewTicker(heartbeatInterval) go func() { for { select { case <-zombieTicker.C: zombieApp.Register() case <-runningTicker.C: runningApp.Register() } } }() zombieApp.VerifyAppStatus(200, c) // Give enough time to register multiple times time.Sleep(heartbeatInterval * 3) // kill registration ticker => kill app (must be before stopping NATS since app.Register is fake and queues messages in memory) zombieTicker.Stop() natsPort := s.natsPort s.stopNats() // Give router time to make a bad decision (i.e. prune routes) time.Sleep(staleCheckInterval + staleThreshold + 250*time.Millisecond) // While NATS is down no routes should go down zombieApp.VerifyAppStatus(200, c) runningApp.VerifyAppStatus(200, c) s.startNats(natsPort) // Right after NATS starts up all routes should stay up zombieApp.VerifyAppStatus(200, c) runningApp.VerifyAppStatus(200, c) zombieGone := make(chan bool) go func() { for { // Finally the zombie is cleaned up. Maybe proactively enqueue Unregister events in DEA's. err := zombieApp.CheckAppStatus(404) if err != nil { time.Sleep(100 * time.Millisecond) continue } err = runningApp.CheckAppStatus(200) if err != nil { time.Sleep(100 * time.Millisecond) continue } zombieGone <- true break } }() select { case <-zombieGone: case <-time.After(staleCheckInterval + staleThreshold + 5*time.Second): c.Error("Zombie app was not pruned.") } }