Skip to content

Commit

Permalink
Fix NanoTimeTocurrentTimeMillisTest on Windows
Browse files Browse the repository at this point in the history
Patch by pmotta; reviewed by aweisberg for CASSANDRA-10139
  • Loading branch information
pauloricardomg authored and jmckenzie-dev committed Aug 24, 2015
1 parent 4994f0c commit 06a053d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Expand Up @@ -46,7 +46,7 @@ public class NanoTimeToCurrentTimeMillis
* There is also the issue of how scalable nanoTime() and currentTimeMillis() are which is a moving target.
*
* These timestamps don't order with System.currentTimeMillis() because currentTimeMillis() can tick over
* before this one does. I have seen it behind by as much as 2 milliseconds.
* before this one does. I have seen it behind by as much as 2ms on Linux and 25ms on Windows.
*/
public static final long convert(long nanoTime)
{
Expand Down
Expand Up @@ -40,13 +40,19 @@ public void testTimestampOrdering() throws Exception
}
Thread.sleep(1);
}
nowNanos = Math.max(now, System.nanoTime());

nowNanos = Math.max(nowNanos, System.nanoTime());
long convertedNow = NanoTimeToCurrentTimeMillis.convert(nowNanos);
assertTrue("convertedNow = " + convertedNow + " lastConverted = " + lastConverted + " in iteration " + ii, convertedNow >= (lastConverted - 1));
lastConverted = convertedNow;
//Seems to be off by as much as two milliseconds sadly
assertTrue("now = " + now + " convertedNow = " + convertedNow + " in iteration " + ii, (now - 2) <= convertedNow);

int maxDiff = FBUtilities.isWindows()? 15 : 1;
assertTrue("convertedNow = " + convertedNow + " lastConverted = " + lastConverted + " in iteration " + ii,
convertedNow >= (lastConverted - maxDiff));

maxDiff = FBUtilities.isWindows()? 25 : 2;
assertTrue("now = " + now + " convertedNow = " + convertedNow + " in iteration " + ii,
(maxDiff - 2) <= convertedNow);

lastConverted = convertedNow;
}
}
}

0 comments on commit 06a053d

Please sign in to comment.