Skip to content

Commit

Permalink
Update new time tests to prevent false positives.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davecgh committed Oct 11, 2014
1 parent e1c622c commit b4c55ae
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions mediantime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit b4c55ae

Please sign in to comment.