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)
}
Esempio n. 2
0
func (s *RouterSuite) TestRouterSendsStartOnConnect(c *C) {
	started := make(chan bool)

	s.router.mbusClient.Subscribe("router.start", func([]byte) {
		started <- true
	})

	mbus.StopNats(s.natsServerCmd)
	s.natsServerCmd = mbus.StartNats(int(s.natsPort))
	<-s.WaitUntilNatsIsUp()

	select {
	case <-started:
	case <-time.After(500 * time.Millisecond):
		c.Error("Did not receive router.start!")
	}
}
Esempio n. 3
0
func (s *RouterSuite) TearDownSuite(c *C) {
	mbus.StopNats(s.natsServerCmd)
}