From 5c9e29c723aac9b774c1875988e2eeb091fcc55d Mon Sep 17 00:00:00 2001 From: Theo Date: Wed, 8 May 2019 16:51:09 +0200 Subject: [PATCH] Fix a race condition in a test It's hard to set this up properly, the cancel request needs to be sent before the GetQueryExecution response with the successful status is returned. Using the number of requests sent works better since it's coupled with the mechanism that blocks the request. --- src/test/java/io/burt/athena/AthenaStatementTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/burt/athena/AthenaStatementTest.java b/src/test/java/io/burt/athena/AthenaStatementTest.java index fe160f9..294bc23 100644 --- a/src/test/java/io/burt/athena/AthenaStatementTest.java +++ b/src/test/java/io/burt/athena/AthenaStatementTest.java @@ -422,9 +422,6 @@ void throwsAnException() { class WhenCalledAfterExecute { @Test void sendsACancelRequest() throws Exception { - queryExecutionHelper.queueStartQueryResponse("Q1234"); - queryExecutionHelper.queueGetQueryExecutionResponse(QueryExecutionState.SUCCEEDED); - ResultSet rs = statement.executeQuery("SELECT 1"); queryExecutionHelper.blockGetQueryExecutionResponse(); queryExecutionHelper.queueStartQueryResponse("Q2345"); queryExecutionHelper.queueGetQueryExecutionResponse(QueryExecutionState.RUNNING); @@ -437,7 +434,8 @@ void sendsACancelRequest() throws Exception { } }); runner.start(); - while (!rs.isClosed()) { + while (queryExecutionHelper.getQueryExecutionRequests().size() == 0) { + Thread.sleep(1); } statement.cancel(); queryExecutionHelper.unblockGetQueryExecutionResponse();