Changed test failure handler to Fatalf(), added comment

pull/2408/head
David Kaltschmidt 2017-11-19 21:06:35 +01:00
parent 79caf5342e
commit 3c5d207a53
1 changed files with 5 additions and 4 deletions

View File

@ -24,17 +24,17 @@ func TestTimerGroupNewTimer(t *testing.T) {
tg := NewTimerGroup() tg := NewTimerGroup()
timer := tg.GetTimer(ExecTotalTime) timer := tg.GetTimer(ExecTotalTime)
if duration := timer.Duration(); duration != 0 { if duration := timer.Duration(); duration != 0 {
t.Errorf("Expected duration of 0, but it was %f instead.", duration) t.Fatalf("Expected duration of 0, but it was %f instead.", duration)
} }
minimum := 2 * time.Millisecond minimum := 2 * time.Millisecond
timer.Start() timer.Start()
time.Sleep(minimum) time.Sleep(minimum)
timer.Stop() timer.Stop()
if duration := timer.Duration(); duration == 0 { if duration := timer.Duration(); duration == 0 {
t.Errorf("Expected duration greater than 0, but it was %f instead.", duration) t.Fatalf("Expected duration greater than 0, but it was %f instead.", duration)
} }
if elapsed := timer.ElapsedTime(); elapsed < minimum { if elapsed := timer.ElapsedTime(); elapsed < minimum {
t.Errorf("Expected elapsed time to be greater than time slept, elapsed was %d, and time slept was %d.", elapsed.Nanoseconds(), minimum) t.Fatalf("Expected elapsed time to be greater than time slept, elapsed was %d, and time slept was %d.", elapsed.Nanoseconds(), minimum)
} }
} }
@ -48,8 +48,9 @@ func TestQueryStatsWithTimers(t *testing.T) {
var qs *QueryStats var qs *QueryStats
qs = NewQueryStats(tg) qs = NewQueryStats(tg)
actual, _ := json.Marshal(qs) actual, _ := json.Marshal(qs)
// Timing value is one of multiple fields, unit is seconds (float).
match, _ := regexp.MatchString(`[,{]"execTotalTime":\d+\.\d+[,}]`, string(actual)) match, _ := regexp.MatchString(`[,{]"execTotalTime":\d+\.\d+[,}]`, string(actual))
if !match { if !match {
t.Errorf("Expected timings with one non-zero entry, but got %s.", actual) t.Fatalf("Expected timings with one non-zero entry, but got %s.", actual)
} }
} }