8049884: Reduce possible timing noise in com/sun/jndi/ldap/LdapTimeoutTest.java

Reviewed-by: vinnie
This commit is contained in:
Pavel Rappo 2014-07-11 14:53:55 +01:00
parent 1aed2210e0
commit 58366bce32

View File

@ -23,6 +23,7 @@
/** /**
* @test * @test
* @run main/othervm LdapTimeoutTest
* @bug 7094377 8000487 6176036 7056489 * @bug 7094377 8000487 6176036 7056489
* @summary Timeout tests for ldap * @summary Timeout tests for ldap
*/ */
@ -147,7 +148,7 @@ public class LdapTimeoutTest {
void deadServerNoTimeout(Hashtable env) { void deadServerNoTimeout(Hashtable env) {
InitialContext ctx = null; InitialContext ctx = null;
ScheduledFuture killer = killSwitch(30_000); ScheduledFuture killer = killSwitch(30_000);
long start = System.nanoTime(); long start = System.currentTimeMillis();
try { try {
ctx = new InitialDirContext(env); ctx = new InitialDirContext(env);
SearchControls scl = new SearchControls(); SearchControls scl = new SearchControls();
@ -157,13 +158,11 @@ public class LdapTimeoutTest {
// shouldn't reach here // shouldn't reach here
fail(); fail();
} catch (NamingException e) { } catch (NamingException e) {
long end = System.nanoTime(); long elapsed = System.currentTimeMillis() - start;
long elapsed = NANOSECONDS.toMillis(end - start);
if (elapsed < Connection.DEFAULT_READ_TIMEOUT_MILLIS) { if (elapsed < Connection.DEFAULT_READ_TIMEOUT_MILLIS) {
System.err.printf( System.err.printf("fail: timeout should be at least %s ms, " +
"fail: timeout should be at least %s ms, actual time is %s ms", "actual time is %s ms%n",
Connection.DEFAULT_READ_TIMEOUT_MILLIS, Connection.DEFAULT_READ_TIMEOUT_MILLIS, elapsed);
elapsed);
e.printStackTrace(); e.printStackTrace();
fail(); fail();
} else { } else {