Skip to content

Commit

Permalink
Replace assertUntilTimeout with assertEventually
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Nov 21, 2020
1 parent 66ffde0 commit 24092e3
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static io.prestosql.testing.TestingAccessControlManager.privilege;
import static io.prestosql.testing.TestingSession.TESTING_CATALOG;
import static io.prestosql.testing.assertions.Assert.assertEquals;
import static io.prestosql.testing.assertions.Assert.assertEventually;
import static io.prestosql.testing.sql.TestTable.randomTableSuffix;
import static java.lang.String.format;
import static java.lang.Thread.currentThread;
Expand Down Expand Up @@ -1011,15 +1012,15 @@ public void testQueryLoggingCount()
{
QueryManager queryManager = getDistributedQueryRunner().getCoordinator().getQueryManager();
executeExclusively(() -> {
assertUntilTimeout(
assertEventually(
new Duration(1, MINUTES),
() -> assertEquals(
queryManager.getQueries().stream()
.map(BasicQueryInfo::getQueryId)
.map(queryManager::getFullQueryInfo)
.filter(info -> !info.isFinalQueryInfo())
.collect(toList()),
ImmutableList.of()),
new Duration(1, MINUTES));
ImmutableList.of()));

// We cannot simply get the number of completed queries as soon as all the queries are completed, because this counter may not be up-to-date at that point.
// The completed queries counter is updated in a final query info listener, which is called eventually.
Expand All @@ -1035,9 +1036,9 @@ public void testQueryLoggingCount()
assertQueryFails("SELECT * FROM " + tableName, ".*Table .* does not exist");

// TODO: Figure out a better way of synchronization
assertUntilTimeout(
() -> assertEquals(dispatchManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4),
new Duration(1, MINUTES));
assertEventually(
new Duration(1, MINUTES),
() -> assertEquals(dispatchManager.getStats().getCompletedQueries().getTotalCount() - beforeCompletedQueriesCount, 4));
assertEquals(dispatchManager.getStats().getSubmittedQueries().getTotalCount() - beforeSubmittedQueriesCount, 4);
});
}
Expand All @@ -1057,23 +1058,6 @@ private <T> T waitUntilStable(Supplier<T> computation, Duration timeout)
throw new UncheckedTimeoutException();
}

private static void assertUntilTimeout(Runnable assertion, Duration timeout)
{
long start = System.nanoTime();
while (!currentThread().isInterrupted()) {
try {
assertion.run();
return;
}
catch (AssertionError e) {
if (nanosSince(start).compareTo(timeout) > 0) {
throw e;
}
}
sleepUninterruptibly(50, MILLISECONDS);
}
}

@Test
public void testShowSchemasFromOther()
{
Expand Down

0 comments on commit 24092e3

Please sign in to comment.