+func (suite *VesmgrTestSuite) TestMainLoopVesagentError() {
+ if os.Getenv("TEST_VESPA_EXIT") == "1" {
+ // we're run in a new process, now make vesmgr main loop exit
+ go suite.vesmgr.servRequest()
+ suite.vesmgr.chVesagent <- errors.New("vesagent killed")
+ // we should never actually end up to this sleep, since the runVesmgr should exit
+ time.Sleep(3 * time.Second)
+ return
+ }
+
+ // Run the vesmgr exit test as a separate process
+ cmd := exec.Command(os.Args[0], "-test.run", "TestVesMgrSuite", "-testify.m", "TestMainLoopVesagentError")
+ cmd.Env = append(os.Environ(), "TEST_VESPA_EXIT=1")
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ err := cmd.Run()
+ // check that vesmgr existed with status 1
+
+ e, ok := err.(*exec.ExitError)
+ suite.True(ok)
+ suite.Equal("exit status 1", e.Error())
+}
+
+func (suite *VesmgrTestSuite) TestWaitSubscriptionLoopRespondsSupervisionAndBreaksWhenReceivedSubsNotif() {
+ go func() {
+ time.Sleep(time.Second)
+ ch := make(chan string)
+ suite.vesmgr.chSupervision <- ch
+ suite.Equal("OK", <-ch)
+ suite.vesmgr.chSupervision <- ch
+ suite.Equal("OK", <-ch)
+ suite.vesmgr.chXAppSubscriptions <- subscriptionNotification{true, nil, ""}
+ }()
+
+ suite.vesmgr.waitSubscriptionLoop()
+}
+
+func (suite *VesmgrTestSuite) TestEmptyNotificationChannelReadsAllMsgsFromCh() {
+ go func() {
+ for i := 0; i < 11; i++ {
+ suite.vesmgr.chXAppNotifications <- []byte("hello")
+ }
+ }()
+ time.Sleep(500 * time.Millisecond)
+ <-suite.vesmgr.chXAppNotifications
+ suite.vesmgr.emptyNotificationsChannel()
+ select {
+ case <-suite.vesmgr.chXAppNotifications:
+ suite.Fail("Got unexpected notification")
+ default:
+ // ok
+ }
+}
+
+func (suite *VesmgrTestSuite) TestVespaKilling() {
+ suite.vesmgr.vesagent = makeRunner("sleep", "20")
+ suite.vesmgr.startVesagent()
+ suite.NotNil(suite.vesmgr.killVespa())
+}
+
+func (suite *VesmgrTestSuite) TestVespaKillingAlreadyKilled() {
+ suite.vesmgr.vesagent = makeRunner("sleep", "20")
+ suite.vesmgr.startVesagent()
+ suite.NotNil(suite.vesmgr.killVespa())
+ // Just check that second kill does not block execution
+ suite.NotNil(suite.vesmgr.killVespa())
+}