Update new time tests to prevent false positives.
The new median time tests perform a comparsion of the adjusted time returned from the median time source to the expected value. However, since time is always moving, it is possible the current time between the call to the adjusted time function and the current time taken in the tests for comparison just after the call differ by a second due to a boundary condition. So, this commit modifies the tests to allow for this condition.
This commit is contained in:
parent
e1c622c4cf
commit
b4c55aee28
1 changed files with 10 additions and 5 deletions
|
@ -84,12 +84,17 @@ func TestMedianTime(t *testing.T) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustedTime := time.Unix(filter.AdjustedTime().Unix(), 0)
|
// Since it is possible that the time.Now call in AdjustedTime
|
||||||
wantTime := time.Now().Add(filter.Offset())
|
// and the time.Now call here in the tests will be off by one
|
||||||
wantTime = time.Unix(wantTime.Unix(), 0)
|
// second, allow a fudge factor to compensate.
|
||||||
if !adjustedTime.Equal(wantTime) {
|
adjustedTime := filter.AdjustedTime()
|
||||||
|
now := time.Unix(time.Now().Unix(), 0)
|
||||||
|
wantTime := now.Add(filter.Offset())
|
||||||
|
wantTime2 := now.Add(filter.Offset() - time.Second)
|
||||||
|
if !adjustedTime.Equal(wantTime) && !adjustedTime.Equal(wantTime2) {
|
||||||
t.Errorf("AdjustedTime #%d: unexpected result -- got %v, "+
|
t.Errorf("AdjustedTime #%d: unexpected result -- got %v, "+
|
||||||
"want %v", i, adjustedTime, wantTime)
|
"want %v or %v", i, adjustedTime, wantTime,
|
||||||
|
wantTime2)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue