This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
commit 18296df22ac1d7f7074f77f20809122cd3314e9b Author: Timothy Bish <[email protected]> AuthorDate: Fri Dec 15 12:22:53 2023 -0500 PROTON-2784 Better detect test failure when connections drop Detect that a connection has dropped but unreachable expectations exist --- .../qpid/protonj2/test/driver/AMQPTestDriver.java | 26 +++++++++++-------- .../protonj2/test/driver/ProtonTestClientTest.java | 29 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/AMQPTestDriver.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/AMQPTestDriver.java index 39b32cd4..91a4e53a 100644 --- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/AMQPTestDriver.java +++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/AMQPTestDriver.java @@ -270,17 +270,21 @@ public class AMQPTestDriver implements Consumer<ByteBuffer> { // Check if the currently pending scripted expectation is for the connection // to drop in which case we remove it and unblock any waiters on the script // to complete, if this is the final scripted entry. - while (true) { - final ScriptedElement scriptEntry = script.peek(); - - if (scriptEntry instanceof ConnectionDropExpectation) { - processScript(script.poll()); - return; - } else if (scriptEntry != null && scriptEntry.isOptional()) { - script.poll(); - } else { - return; - } + if (!script.isEmpty()) { + do { + final ScriptedElement scriptEntry = script.peek(); + + if (scriptEntry instanceof ConnectionDropExpectation) { + processScript(script.poll()); + return; + } else if (scriptEntry.isOptional()) { + script.poll(); + } else { + signalFailure(new AssertionError(String.format( + "Scripted elements remaining after connection dropped: %d", script.size()))); + return; + } + } while (!script.isEmpty()); } } } diff --git a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestClientTest.java b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestClientTest.java index f3c533aa..e4036867 100644 --- a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestClientTest.java +++ b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestClientTest.java @@ -103,10 +103,12 @@ class ProtonTestClientTest extends TestPeerTestsBase { peer.expectOpen().respond(); peer.expectBegin().respond(); peer.expectAttach().respond(); + peer.expectConnectionToDrop(); peer.expectAMQPHeader().respondWithAMQPHeader(); peer.expectOpen().respond(); peer.expectBegin().respond(); peer.expectAttach().respond(); + peer.expectConnectionToDrop(); peer.start(); URI remoteURI = peer.getServerURI(); @@ -145,6 +147,7 @@ class ProtonTestClientTest extends TestPeerTestsBase { peer.waitForScriptToComplete(5, TimeUnit.SECONDS); } } + @Test public void testClientDetectsUnexpectedPerformativeResponseToAMQPHeader() throws Exception { try (ProtonTestServer peer = new ProtonTestServer()) { @@ -430,4 +433,30 @@ class ProtonTestClientTest extends TestPeerTestsBase { peer.waitForScriptToComplete(5, TimeUnit.SECONDS); } } + + @Test + public void testConnectionDropTriggerQuickTestFaulure() throws Exception { + try (ProtonTestServer peer = new ProtonTestServer()) { + peer.expectSASLPlainConnect("test", "test"); + peer.expectOpen().respond(); + peer.expectClose().respond(); + peer.start(); + + URI remoteURI = peer.getServerURI(); + + ProtonTestClient client = new ProtonTestClient(); + + client.connect(remoteURI.getHost(), remoteURI.getPort()); + client.triggerClientSaslPlainConnect("test", "test"); + + client.waitForScriptToComplete(5, TimeUnit.SECONDS); + client.close(); + + LOG.info("Test started, peer listening on: {}", remoteURI); + + // We want this to fail as soon as the connection closes since + // there is no way for the script to complete at this point. + assertThrows(AssertionError.class, () -> peer.waitForScriptToComplete()); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
