Esempio n. 1
0
func (s *RouterSuite) TestVarz(c *C) {
	app := test.NewGreetApp([]string{"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()
}
Esempio n. 2
0
func (s *IntegrationSuite) TestNatsConnectivity(c *C) {
	natsPort := nextAvailPort()
	cmd := mbus.StartNats(int(natsPort))

	proxyPort := nextAvailPort()
	statusPort := nextAvailPort()

	s.Config = spec.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)
}
Esempio n. 3
0
func (s *RouterSuite) TestRegisterUnregister(c *C) {
	app := test.NewGreetApp([]string{"test.vcap.me"}, s.Config.Port, s.natsClient, 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)
}
Esempio n. 4
0
func (s *IntegrationSuite) TestNatsConnectivity(c *C) {
	natsPort := nextAvailPort()
	s.natsServer = spec.NewNatsServer(natsPort, fmt.Sprintf("/tmp/router_nats_test-%d.pid", natsPort))
	defer s.natsServer.Stop()

	err := s.natsServer.Start()
	c.Assert(err, IsNil)

	proxyPort := nextAvailPort()
	statusPort := nextAvailPort()

	s.Config = spec.SpecConfig(natsPort, statusPort, proxyPort)
	s.Config.PruneStaleDropletsInterval = 5 * time.Second

	s.router = NewRouter(s.Config)
	go s.router.Run()

	s.natsClient = s.router.natsClient

	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.natsClient, 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)

	s.natsServer.Stop()

	time.Sleep(staleCheckInterval + staleThreshold + 1*time.Second)

	app.VerifyAppStatus(200, c)
}