예제 #1
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)
}
예제 #2
0
func (s *RouterSuite) SetUpSuite(c *C) {
	natsPort := nextAvailPort()

	s.natsServer = spec.NewNatsServer(natsPort, fmt.Sprintf("/tmp/router_nats_test-%d.pid", natsPort))
	err := s.natsServer.Start()
	c.Assert(err, IsNil)

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

	s.Config = spec.SpecConfig(natsPort, statusPort, proxyPort)

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

	s.natsClient = s.router.natsClient
}
예제 #3
0
func (s *RouterSuite) SetUpSuite(c *C) {
	natsPort := nextAvailPort()
	s.natsServer = spec.NewNatsServer(natsPort, "/tmp/router_nats_test.pid")
	err := s.natsServer.Start()
	c.Assert(err, IsNil)

	s.proxyPort = nextAvailPort()
	statusPort := nextAvailPort()

	s.Config = config.DefaultConfig()

	s.Config.Port = s.proxyPort
	s.Config.Index = 2
	s.Config.TraceKey = "my_trace_key"

	// Hardcode the IP to localhost to avoid leaving the machine while running tests
	s.Config.Ip = "127.0.0.1"

	s.Config.PublishStartMessageInterval = 10 * time.Millisecond
	s.Config.PruneStaleDropletsInterval = 0
	s.Config.DropletStaleThreshold = 0
	s.Config.PublishActiveAppsInterval = 0

	s.Config.Status = config.StatusConfig{
		Port: statusPort,
		User: "******",
		Pass: "******",
	}

	s.Config.Nats = config.NatsConfig{
		Host: fmt.Sprintf("localhost:%d", natsPort),
	}

	s.Config.Logging = config.LoggingConfig{
		File:  "/dev/null",
		Level: "info",
	}

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

	s.natsClient = startNATS(fmt.Sprintf("localhost:%d", natsPort), "", "")
}