Skip to content
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

SNOW-1787626: Fix flaky test ConnectionLatestIT.testAsyncQueryOpenAndCloseConnection #1974

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ public void testAsyncQueryOpenAndCloseConnection()
throws SQLException, IOException, InterruptedException {
// open connection and run asynchronous query
String queryID = null;
QueryStatusV2 statusV2 = null;
try (Connection con = getConnection();
Statement statement = con.createStatement();
ResultSet rs1 =
Expand All @@ -288,7 +287,7 @@ public void testAsyncQueryOpenAndCloseConnection()
await()
.atMost(Duration.ofSeconds(5))
.until(() -> sfrs.getStatusV2().getStatus(), not(equalTo(QueryStatus.NO_DATA)));
statusV2 = sfrs.getStatusV2();
QueryStatusV2 statusV2 = sfrs.getStatusV2();
// Query should take 60 seconds so should be running
assertEquals(QueryStatus.RUNNING, statusV2.getStatus());
assertEquals(QueryStatus.RUNNING.name(), statusV2.getName());
Expand All @@ -305,7 +304,7 @@ public void testAsyncQueryOpenAndCloseConnection()
assertEquals(SqlState.INVALID_PARAMETER_VALUE, e.getSQLState());
}
try (ResultSet rs = con.unwrap(SnowflakeConnection.class).createResultSet(queryID)) {
statusV2 = rs.unwrap(SnowflakeResultSet.class).getStatusV2();
QueryStatusV2 statusV2 = rs.unwrap(SnowflakeResultSet.class).getStatusV2();
// Assert status of query is a success
assertEquals(QueryStatus.SUCCESS, statusV2.getStatus());
assertEquals("No error reported", statusV2.getErrorMessage());
Expand All @@ -318,27 +317,16 @@ public void testAsyncQueryOpenAndCloseConnection()
.unwrap(SnowflakeStatement.class)
.executeAsyncQuery("select * from nonexistentTable")) {
Thread.sleep(100);
statusV2 = rs1.unwrap(SnowflakeResultSet.class).getStatusV2();
// when GS response is slow, allow up to 1 second of retries to get final query status
SnowflakeResultSet sfrs1 = rs1.unwrap(SnowflakeResultSet.class);
await()
.atMost(Duration.ofSeconds(10))
.until(
() -> {
QueryStatus qs = sfrs1.getStatusV2().getStatus();
return !(qs == QueryStatus.NO_DATA || qs == QueryStatus.RUNNING);
});
// If GS response is too slow to return data, do nothing to avoid flaky test failure. If
// response has returned,
// assert it is the error message that we are expecting.
if (statusV2.getStatus() != QueryStatus.NO_DATA) {
assertEquals(QueryStatus.FAILED_WITH_ERROR, statusV2.getStatus());
assertEquals(2003, statusV2.getErrorCode());
assertEquals(
"SQL compilation error:\n"
+ "Object 'NONEXISTENTTABLE' does not exist or not authorized.",
statusV2.getErrorMessage());
}
.until(() -> sfrs1.getStatusV2().getStatus() == QueryStatus.FAILED_WITH_ERROR);
statusV2 = sfrs1.getStatusV2();
assertEquals(2003, statusV2.getErrorCode());
assertEquals(
"SQL compilation error:\n"
+ "Object 'NONEXISTENTTABLE' does not exist or not authorized.",
statusV2.getErrorMessage());
}
}
}
Expand Down
Loading