-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a randomized start before running CheckMonitors. #546
Changes from 3 commits
60dacec
2e58f54
d82ef7b
f2bd641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's lower these timing values significantly. I think we can safely use a low value like 10ms for the Interval, and then use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, |
||
|
||
// 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), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just print a
time.Duration
directly here as a string, it will get formatted in a nice, human-friendly way by itsString()
method. That way we don't have to explicitly cast to anint
, and we get a more accurate value in the log.