From d82ef7bb8c69acfbea054939dd52fde4b7b3388c Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Wed, 17 Dec 2014 22:39:11 -0500 Subject: [PATCH] Test that staggered checks run within the defined interval. --- command/agent/check_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/command/agent/check_test.go b/command/agent/check_test.go index 19e087c67e..62cbafb7c4 100644 --- a/command/agent/check_test.go +++ b/command/agent/check_test.go @@ -65,6 +65,34 @@ func TestCheckMonitor_BadCmd(t *testing.T) { expectStatus(t, "foobarbaz", structs.HealthCritical) } +func TestCheckMonitor_RandomStagger(t *testing.T) { + mock := &MockNotify{ + state: make(map[string]string), + updates: make(map[string]int), + output: make(map[string]string), + } + check := &CheckMonitor{ + Notify: mock, + CheckID: "foo", + Script: "exit 0", + Interval: 5 * time.Second, + Logger: log.New(os.Stderr, "", log.LstdFlags), + } + check.Start() + defer check.Stop() + + time.Sleep(6 * time.Second) + + // Should have at least 1 update + if mock.updates["foo"] < 1 { + t.Fatalf("should have 1 updates %v", mock.updates) + } + + if mock.state["foo"] != structs.HealthPassing { + t.Fatalf("should be %v %v", structs.HealthPassing, mock.state) + } +} + func TestCheckMonitor_LimitOutput(t *testing.T) { mock := &MockNotify{ state: make(map[string]string),