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:
Dave Collins 2014-10-11 14:49:35 -05:00
parent e1c622c4cf
commit b4c55aee28

View file

@ -84,12 +84,17 @@ func TestMedianTime(t *testing.T) {
continue
}
adjustedTime := time.Unix(filter.AdjustedTime().Unix(), 0)
wantTime := time.Now().Add(filter.Offset())
wantTime = time.Unix(wantTime.Unix(), 0)
if !adjustedTime.Equal(wantTime) {
// Since it is possible that the time.Now call in AdjustedTime
// and the time.Now call here in the tests will be off by one
// second, allow a fudge factor to compensate.
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, "+
"want %v", i, adjustedTime, wantTime)
"want %v or %v", i, adjustedTime, wantTime,
wantTime2)
continue
}
}