Skip to content
Permalink
Browse files
remove more currentTimeMillis in order to get tests to be more reliab…
…le (#1647)

* remove more currentTimeMillis in order to get tests to be more reliable
  • Loading branch information
davecramer committed Dec 13, 2019
1 parent ea2ca87 commit 617f0487adddb6601e681e25006e5555bc644c3e
@@ -26,7 +26,7 @@ public class GlobalHostStatusTracker {
* @param hostStatus Latest known status for the host.
*/
public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
long now = System.nanoTime() / 1000;
long now = System.nanoTime() / 1000000;
synchronized (hostStatusMap) {
HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
if (hostSpecStatus == null) {
@@ -49,7 +49,7 @@ public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
static List<HostSpec> getCandidateHosts(HostSpec[] hostSpecs,
HostRequirement targetServerType, long hostRecheckMillis) {
List<HostSpec> candidates = new ArrayList<HostSpec>(hostSpecs.length);
long latestAllowedUpdate = System.nanoTime() / 1000 - hostRecheckMillis;
long latestAllowedUpdate = System.nanoTime() / 1000000 - hostRecheckMillis;
synchronized (hostStatusMap) {
for (HostSpec hostSpec : hostSpecs) {
HostSpecStatus hostInfo = hostStatusMap.get(hostSpec);
@@ -688,16 +688,16 @@ public void testSetQueryTimeout() throws SQLException {
boolean cancelReceived = false;
try {
stmt.setQueryTimeout(1);
start = System.currentTimeMillis();
start = System.nanoTime();
stmt.execute("select pg_sleep(10)");
} catch (SQLException sqle) {
// state for cancel
if ("57014".equals(sqle.getSQLState())) {
cancelReceived = true;
}
}
long duration = System.currentTimeMillis() - start;
if (!cancelReceived || duration > 5000) {
long duration = System.nanoTime() - start;
if (!cancelReceived || duration > (5E9)) {
fail("Query should have been cancelled since the timeout was set to 1 sec."
+ " Cancel state: " + cancelReceived + ", duration: " + duration);
}
@@ -722,11 +722,11 @@ public void testLongQueryTimeout() throws SQLException {
public void testShortQueryTimeout() throws SQLException {
assumeLongTest();

long deadLine = System.currentTimeMillis() + 10000;
long deadLine = System.nanoTime() + 10000 * 1000000;
Statement stmt = con.createStatement();
((PgStatement) stmt).setQueryTimeoutMs(1);
Statement stmt2 = con.createStatement();
while (System.currentTimeMillis() < deadLine) {
while (System.nanoTime() < deadLine) {
try {
// This usually won't time out but scheduler jitter, server load
// etc can cause a timeout.
@@ -869,10 +869,10 @@ public void testCloseInProgressStatement() throws Exception {
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
long start = System.currentTimeMillis();
long start = System.nanoTime();
while (st.getWarnings() == null) {
long dt = System.currentTimeMillis() - start;
if (dt > 10000) {
long dt = System.nanoTime() - start;
if (dt > 10000 * 10000000) {
throw new IllegalStateException("Expected to receive a notice within 10 seconds");
}
}
@@ -963,12 +963,12 @@ public Void call() throws Exception {
*/
@Test
public void testSideStatementFinalizers() throws SQLException {
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(2);
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(2);

final AtomicInteger leaks = new AtomicInteger();
final AtomicReference<Throwable> cleanupFailure = new AtomicReference<Throwable>();

for (int q = 0; System.currentTimeMillis() < deadline || leaks.get() < 10000; q++) {
for (int q = 0; System.nanoTime() < deadline || leaks.get() < 10000; q++) {
for (int i = 0; i < 100; i++) {
PreparedStatement ps = con.prepareStatement("select " + (i + q));
ps.close();

0 comments on commit 617f048

Please sign in to comment.