Example #1
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("run sets the dispatcher as message handler", func() {
			deps, agent := buildAgent()
			deps.actionDispatcher.DispatchResp = boshhandler.NewValueResponse("pong")

			err := agent.Run()

			assert.NoError(GinkgoT(), err)
			assert.True(GinkgoT(), deps.handler.ReceivedRun)

			req := boshhandler.NewRequest("reply to me!", "some action", []byte("some payload"))
			resp := deps.handler.Func(req)

			assert.Equal(GinkgoT(), deps.actionDispatcher.DispatchReq, req)
			assert.Equal(GinkgoT(), resp, deps.actionDispatcher.DispatchResp)
		})
		It("run sets up heartbeats", func() {

			deps, agent := buildAgent()
			deps.platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
				Load: []string{"a", "b", "c"},
			}

			err := agent.Run()
			assert.NoError(GinkgoT(), err)
			assert.False(GinkgoT(), deps.handler.TickHeartbeatsSent)

			assert.True(GinkgoT(), deps.handler.InitialHeartbeatSent)
			assert.Equal(GinkgoT(), "heartbeat", deps.handler.SendToHealthManagerTopic)
			time.Sleep(5 * time.Millisecond)
			assert.True(GinkgoT(), deps.handler.TickHeartbeatsSent)

			hb := deps.handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)
			assert.Equal(GinkgoT(), deps.platform.FakeVitalsService.GetVitals, hb.Vitals)
		})
		It("run sets the callback for job failures monitoring", func() {

			deps, agent := buildAgent()

			builtAlert := boshalert.Alert{Id: "some built alert id"}
			deps.alertBuilder.BuildAlert = builtAlert

			err := agent.Run()
			assert.NoError(GinkgoT(), err)
			assert.NotEqual(GinkgoT(), deps.handler.SendToHealthManagerTopic, "alert")

			failureAlert := boshalert.MonitAlert{Id: "some random id"}
			deps.jobSupervisor.OnJobFailure(failureAlert)

			assert.Equal(GinkgoT(), deps.alertBuilder.BuildInput, failureAlert)
			assert.Equal(GinkgoT(), deps.handler.SendToHealthManagerTopic, "alert")
			assert.Equal(GinkgoT(), deps.handler.SendToHealthManagerPayload, builtAlert)
		})
	})
}
Example #2
0
func TestRunSetsTheDispatcherAsMessageHandler(t *testing.T) {
	deps, agent := buildAgent()
	deps.actionDispatcher.DispatchResp = boshhandler.NewValueResponse("pong")

	err := agent.Run()

	assert.NoError(t, err)
	assert.True(t, deps.handler.ReceivedRun)

	req := boshhandler.NewRequest("reply to me!", "some action", []byte("some payload"))
	resp := deps.handler.Func(req)

	assert.Equal(t, deps.actionDispatcher.DispatchReq, req)
	assert.Equal(t, resp, deps.actionDispatcher.DispatchResp)
}
Example #3
0
func TestRunSetsTheCallbackForJobFailuresMonitoring(t *testing.T) {
	deps, agent := buildAgent()

	builtAlert := boshalert.Alert{Id: "some built alert id"}
	deps.alertBuilder.BuildAlert = builtAlert

	err := agent.Run()
	assert.NoError(t, err)
	assert.NotEqual(t, deps.handler.SendToHealthManagerTopic, "alert")

	failureAlert := boshalert.MonitAlert{Id: "some random id"}
	deps.jobSupervisor.OnJobFailure(failureAlert)

	assert.Equal(t, deps.alertBuilder.BuildInput, failureAlert)
	assert.Equal(t, deps.handler.SendToHealthManagerTopic, "alert")
	assert.Equal(t, deps.handler.SendToHealthManagerPayload, builtAlert)
}
Example #4
0
func TestRunSetsUpHeartbeats(t *testing.T) {
	deps, agent := buildAgent()
	deps.platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
		Load: []string{"a", "b", "c"},
	}

	err := agent.Run()
	assert.NoError(t, err)
	assert.False(t, deps.handler.TickHeartbeatsSent)

	assert.True(t, deps.handler.InitialHeartbeatSent)
	assert.Equal(t, "heartbeat", deps.handler.SendToHealthManagerTopic)
	time.Sleep(5 * time.Millisecond)
	assert.True(t, deps.handler.TickHeartbeatsSent)

	hb := deps.handler.SendToHealthManagerPayload.(boshmbus.Heartbeat)
	assert.Equal(t, deps.platform.FakeVitalsService.GetVitals, hb.Vitals)
}