From 0ab45d83177eb066bfaf3fff16aa8171d8092b17 Mon Sep 17 00:00:00 2001 From: Valera V Harseko Date: Sat, 19 Sep 2026 10:34:04 +0300 Subject: [PATCH] [#137] Wait for cleanup in RequestDistributorTest.testFailedRequest testFailedRequest returned as soon as getOrThrowUninterruptibly() threw, without waiting for the promise completion listener to remove the request from remoteRequests/localRequests. Since sibling test methods only depend on testNoConnectionRequest, TestNG may run any of them right after testFailedRequest, so their entry assertions could observe the stale entry and fail intermittently. The assertions placed after getOrThrowUninterruptibly() were also unreachable: the call threw before reaching them, so the test never verified its own cleanup. Catch the expected exception explicitly and wait for the maps to drain, as the sibling test methods already do. --- .../common/rpc/RequestDistributorTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/OpenICF-java-framework/connector-framework-rpc/src/test/java/org/forgerock/openicf/common/rpc/RequestDistributorTest.java b/OpenICF-java-framework/connector-framework-rpc/src/test/java/org/forgerock/openicf/common/rpc/RequestDistributorTest.java index fba02bc0..b22cd0d4 100644 --- a/OpenICF-java-framework/connector-framework-rpc/src/test/java/org/forgerock/openicf/common/rpc/RequestDistributorTest.java +++ b/OpenICF-java-framework/connector-framework-rpc/src/test/java/org/forgerock/openicf/common/rpc/RequestDistributorTest.java @@ -251,9 +251,7 @@ public void handleException(Exception error) { } } - @Test(dependsOnMethods = { "testNoConnectionRequest" }, - expectedExceptions = RuntimeException.class, - expectedExceptionsMessageRegExp = "Unknown Test case number") + @Test(dependsOnMethods = { "testNoConnectionRequest" }) public void testFailedRequest() throws Exception { RemoteConnectionHolder, H, TestConnectionContext> connection = getConnection(); @@ -263,7 +261,22 @@ public void testFailedRequest() throws Exception { Assert.assertTrue(server.isOperational()); TestRemoteRequest request = client.trySubmitRequest(new TestRequestFactory(3)); - request.getPromise().getOrThrowUninterruptibly(); + try { + request.getPromise().getOrThrowUninterruptibly(); + Assert.fail("Not Failed"); + } catch (RuntimeException e) { + Assert.assertEquals(e.getMessage(), "Unknown Test case number"); + } + // The promise's completion listeners (which remove this request + // from remoteRequests/localRequests) run after + // getOrThrowUninterruptibly() has already thrown, so wait for + // that cleanup instead of asserting immediately - otherwise the + // next test method's entry assertions can race it. + for (int i = 0; i < 5 && !(client.getRemoteRequests().isEmpty() + && server.getLocalRequests().isEmpty()); i++) { + Reporter.log("Wait for failed request cleanup: " + i, true); + Thread.sleep(1000); // Wait to complete all other threads + } Assert.assertTrue(client.getRemoteRequests().isEmpty()); Assert.assertTrue(server.getLocalRequests().isEmpty()); } finally {