diff --git a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionFailureTest.java b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionFailureTest.java index efd038d3191..71991569095 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionFailureTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/ParallelPhoenixConnectionFailureTest.java @@ -82,6 +82,10 @@ public void testExecuteQueryChainFailure() throws SQLException { doThrow(new SQLException()).when(connSpy1).createStatement(); parallelConn.createStatement().execute("SELECT * FROM SYSTEM.CATALOG"); hbaseTestingUtility.waitFor(WAIT_MS, () -> numStatementsCreatedOnConn2.get() == 3); + // Conn1 can fail on its own executor thread after the caller returns. + // Wait for this failure before the test restores the stub. + hbaseTestingUtility.waitFor(WAIT_MS, + () -> context.getChainOnConn1().isCompletedExceptionally()); doAnswer(answer1).when(connSpy1).createStatement(); // Should still have a successful execution only from conn2 since conn1 errored before parallelConn.createStatement().execute("SELECT * FROM SYSTEM.CATALOG");