Skip to content

Commit

Permalink
SNOW-1787626: Fix flaky test ConnectionLatestIT.testAsyncQueryOpenAnd…
Browse files Browse the repository at this point in the history
…CloseConnection (#1974)
  • Loading branch information
sfc-gh-dprzybysz authored Nov 25, 2024
1 parent 938d846 commit 930f419
Showing 1 changed file with 9 additions and 21 deletions.
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

0 comments on commit 930f419

Please sign in to comment.