Ejemplo n.º 1
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)
}
Ejemplo n.º 2
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)
}
Ejemplo n.º 3
0
func (s *RouterSuite) SetUpSuite(c *C) {
	natsPort := nextAvailPort()

	s.natsServerCmd = mbus.StartNats(int(natsPort))

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

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

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

	<-s.WaitUntilNatsIsUp()
	s.mbusClient = s.router.mbusClient
}
Ejemplo n.º 4
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
}