-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Additional integration test checks #14328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,13 @@ | |
| import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
| import io.airlift.units.Duration; | ||
| import io.trino.Session; | ||
| import io.trino.execution.QueryInfo; | ||
| import io.trino.execution.QueryManager; | ||
| import io.trino.execution.QueryState; | ||
| import io.trino.execution.QueryStats; | ||
| import io.trino.execution.SqlTaskManager; | ||
| import io.trino.execution.TaskId; | ||
| import io.trino.execution.TaskInfo; | ||
| import io.trino.execution.warnings.WarningCollector; | ||
| import io.trino.memory.LocalMemoryManager; | ||
| import io.trino.memory.MemoryPool; | ||
|
|
@@ -56,6 +61,7 @@ | |
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.Optional; | ||
| import java.util.OptionalLong; | ||
| import java.util.function.Consumer; | ||
|
|
@@ -106,6 +112,8 @@ public final void close() | |
| { | ||
| try (afterClassCloser) { | ||
| checkQueryMemoryReleased(); | ||
| checkQueryInfosFinal(); | ||
| checkTasksDone(); | ||
| } | ||
| finally { | ||
| queryRunner = null; | ||
|
|
@@ -116,27 +124,20 @@ public final void close() | |
|
|
||
| private void checkQueryMemoryReleased() | ||
| { | ||
| if (queryRunner == null) { | ||
| return; | ||
| } | ||
| if (!(queryRunner instanceof DistributedQueryRunner)) { | ||
| return; | ||
| } | ||
| DistributedQueryRunner distributedQueryRunner = (DistributedQueryRunner) queryRunner; | ||
| assertEventually( | ||
| tryGetDistributedQueryRunner().ifPresent(runner -> assertEventually( | ||
| new Duration(30, SECONDS), | ||
| new Duration(1, SECONDS), | ||
| () -> { | ||
| List<TestingTrinoServer> servers = distributedQueryRunner.getServers(); | ||
| List<TestingTrinoServer> servers = runner.getServers(); | ||
| for (int serverId = 0; serverId < servers.size(); ++serverId) { | ||
| TestingTrinoServer server = servers.get(serverId); | ||
| assertMemoryPoolReleased(distributedQueryRunner.getCoordinator(), server, serverId); | ||
| assertMemoryPoolReleased(runner.getCoordinator(), server, serverId); | ||
| } | ||
|
|
||
| assertThat(distributedQueryRunner.getCoordinator().getClusterMemoryManager().getClusterTotalMemoryReservation()) | ||
| assertThat(runner.getCoordinator().getClusterMemoryManager().getClusterTotalMemoryReservation()) | ||
| .describedAs("cluster memory reservation") | ||
| .isZero(); | ||
| }); | ||
| })); | ||
| } | ||
|
|
||
| private void assertMemoryPoolReleased(TestingTrinoServer coordinator, TestingTrinoServer server, long serverId) | ||
|
|
@@ -178,6 +179,55 @@ private String describeMemoryPool(TestingTrinoServer coordinator, TestingTrinoSe | |
| return result.toString(); | ||
| } | ||
|
|
||
| private void checkQueryInfosFinal() | ||
| { | ||
| tryGetDistributedQueryRunner().ifPresent(runner -> assertEventually( | ||
| new Duration(30, SECONDS), | ||
| new Duration(1, SECONDS), | ||
| () -> { | ||
| TestingTrinoServer coordinator = runner.getCoordinator(); | ||
| QueryManager queryManager = coordinator.getQueryManager(); | ||
| for (BasicQueryInfo basicQueryInfo : queryManager.getQueries()) { | ||
| QueryId queryId = basicQueryInfo.getQueryId(); | ||
| if (!basicQueryInfo.getState().isDone()) { | ||
| fail("query is expected to be in done state: " + basicQueryInfo.getQuery()); | ||
| } | ||
| QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId); | ||
| if (!queryInfo.isFinalQueryInfo()) { | ||
| fail("QueryInfo is expected to be final: " + basicQueryInfo.getQuery()); | ||
| } | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| private void checkTasksDone() | ||
| { | ||
| tryGetDistributedQueryRunner().ifPresent(runner -> assertEventually( | ||
| new Duration(30, SECONDS), | ||
| new Duration(1, SECONDS), | ||
| () -> { | ||
| QueryManager queryManager = runner.getCoordinator().getQueryManager(); | ||
| List<TestingTrinoServer> servers = runner.getServers(); | ||
| for (TestingTrinoServer server : servers) { | ||
| SqlTaskManager taskManager = server.getTaskManager(); | ||
| List<TaskInfo> taskInfos = taskManager.getAllTaskInfo(); | ||
| for (TaskInfo taskInfo : taskInfos) { | ||
| TaskId taskId = taskInfo.getTaskStatus().getTaskId(); | ||
| QueryId queryId = taskId.getQueryId(); | ||
| String query = "unknown"; | ||
| try { | ||
| query = queryManager.getQueryInfo(queryId).getQuery(); | ||
| } | ||
| catch (NoSuchElementException ignored) { | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: move to previous line
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I move it to the previous line it doesn't pass the style check
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. I have checkstyle set up in IntelliJ and it did not complain. 🤷
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, my Intellij doesn't complain either (though it is trying to format it with a new line when I try to autoformat). But then the check during the build fails. |
||
| if (!taskInfo.getTaskStatus().getState().isDone()) { | ||
| fail("Task is expected to be in done state. TaskId: %s, QueryId: %s, Query: %s ".formatted(taskId, queryId, query)); | ||
| } | ||
| } | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| @Test | ||
| public void ensureTestNamingConvention() | ||
| { | ||
|
|
@@ -536,6 +586,14 @@ protected final DistributedQueryRunner getDistributedQueryRunner() | |
| return (DistributedQueryRunner) queryRunner; | ||
| } | ||
|
|
||
| private Optional<DistributedQueryRunner> tryGetDistributedQueryRunner() | ||
| { | ||
| if (queryRunner != null && queryRunner instanceof DistributedQueryRunner runner) { | ||
| return Optional.of(runner); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| protected Session noJoinReordering() | ||
| { | ||
| return noJoinReordering(JoinDistributionType.PARTITIONED); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,14 +95,14 @@ private QueryError trySelectQuery(String assumedUser) | |
| .build(); | ||
|
|
||
| // start query | ||
| StatementClient client = newStatementClient(httpClient, clientSession, "SELECT * FROM tpch.tiny.nation"); | ||
| try (StatementClient client = newStatementClient(httpClient, clientSession, "SELECT * FROM tpch.tiny.nation")) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: look unrelated - separate commit?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the statement is not closed the query never finishes and doesn't receive a final TaskInfo making the newly introduced check fail
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still should be a preparatory commit. So adding checks and making project actually pass the checks are separate commits. (fixing makes sense even if we do not have checks). |
||
| // wait for query to be fully scheduled | ||
| while (client.isRunning() && !client.currentStatusInfo().getStats().isScheduled()) { | ||
| client.advance(); | ||
| } | ||
|
|
||
| // wait for query to be fully scheduled | ||
| while (client.isRunning() && !client.currentStatusInfo().getStats().isScheduled()) { | ||
| client.advance(); | ||
| return client.currentStatusInfo().getError(); | ||
| } | ||
|
|
||
| return client.currentStatusInfo().getError(); | ||
| } | ||
| finally { | ||
| // close the client since, query is not managed by the client protocol | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there may be some tests which schedule queries in the background and do not necessarily wait for their completion. But we can address that if we see this becoming flaky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one that I found: https://github.com/trinodb/trino/pull/14328/files#diff-c4d608eefc95a8f2dcee82dc30e0ee1f81313dded318f7fa0e381c1e54f4cd46R98.