Skip to content

Commit

Permalink
Pick failing query faster in testOutOfMemoryKiller
Browse files Browse the repository at this point in the history
Within the test, one query should get killed, but the other may not be
killed and run to completion. If the first submitted query happens to
run successfully, the test takes longer to complete.

Inspect queries in order of their completion, not submission.
  • Loading branch information
findepi committed Apr 6, 2022
1 parent e11d9fe commit 8eca03d
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.server.testing.TestingTrinoServer;
import io.trino.spi.QueryId;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.MaterializedResult;
import io.trino.testing.QueryRunner;
import io.trino.tests.tpch.TpchQueryRunnerBuilder;
import org.intellij.lang.annotations.Language;
Expand All @@ -32,7 +33,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -129,16 +132,17 @@ public void testOutOfMemoryKiller()
assertTrue(memoryPool.tryReserve(fakeQueryId, "test", memoryPool.getMaxBytes()));
}

List<Future<?>> queryFutures = new ArrayList<>();
for (int i = 0; i < 2; i++) {
queryFutures.add(executor.submit(() -> queryRunner.execute("" +
int queries = 2;
CompletionService<MaterializedResult> completionService = new ExecutorCompletionService<>(executor);
for (int i = 0; i < queries; i++) {
completionService.submit(() -> queryRunner.execute("" +
"SELECT COUNT(*), clerk " +
"FROM (SELECT clerk FROM orders UNION ALL SELECT dummy FROM blackhole.default.take_30s)" +
"GROUP BY clerk")));
"GROUP BY clerk"));
}

// Wait for queries to start
assertEventually(() -> assertThat(queryRunner.getCoordinator().getQueryManager().getQueries()).hasSize(1 + queryFutures.size()));
assertEventually(() -> assertThat(queryRunner.getCoordinator().getQueryManager().getQueries()).hasSize(1 + queries));

// Wait for one of the queries to die
waitForQueryToBeKilled(queryRunner);
Expand All @@ -152,8 +156,8 @@ public void testOutOfMemoryKiller()
}

assertThatThrownBy(() -> {
for (Future<?> query : queryFutures) {
query.get();
for (int i = 0; i < queries; i++) {
completionService.take().get();
}
})
.isInstanceOf(ExecutionException.class)
Expand Down

0 comments on commit 8eca03d

Please sign in to comment.