From b4c55aee281e90baad00ee210f330d06ccb04093 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sat, 11 Oct 2014 14:49:35 -0500 Subject: [PATCH] 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. --- mediantime_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mediantime_test.go b/mediantime_test.go index 6a4254c5..98e720c7 100644 --- a/mediantime_test.go +++ b/mediantime_test.go @@ -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 } }