From 60a9868689f6e090d036a9b09780c25e5f1fab51 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Thu, 10 Oct 2024 17:11:52 -0400 Subject: [PATCH] Add delay after closing WS connection --- cpp/test/Ice/maxConnections/AllTests.cpp | 44 +++++++++++++--- cpp/test/Ice/maxConnections/Client.cpp | 6 ++- csharp/test/Ice/maxConnections/AllTests.cs | 52 ++++++++++++++++--- csharp/test/Ice/maxConnections/Client.cs | 6 ++- .../test/Ice/maxConnections/AllTests.java | 40 +++++++++++--- .../java/test/Ice/maxConnections/Client.java | 3 ++ 6 files changed, 131 insertions(+), 20 deletions(-) diff --git a/cpp/test/Ice/maxConnections/AllTests.cpp b/cpp/test/Ice/maxConnections/AllTests.cpp index f712b676d19..122cb1bf54b 100644 --- a/cpp/test/Ice/maxConnections/AllTests.cpp +++ b/cpp/test/Ice/maxConnections/AllTests.cpp @@ -13,7 +13,7 @@ using namespace Test; // Verify that we can create connectionCount connections and send a ping on each connection. void -testCreateConnections(TestIntfPrx p, int connectionCount) +testCreateConnections(TestIntfPrx p, int connectionCount, function postCloseDelay) { cout << "testing the creation of " << connectionCount << " connections... " << flush; vector connectionList; @@ -29,12 +29,18 @@ testCreateConnections(TestIntfPrx p, int connectionCount) { connection->close().get(); } + + if (postCloseDelay) + { + postCloseDelay(); + } + cout << "ok" << endl; } // Verify that we can create connectionCount connections and send a ping on each connection. void -testCreateConnectionsWithMax(TestIntfPrx p, int max) +testCreateConnectionsWithMax(TestIntfPrx p, int max, function postCloseDelay) { cout << "testing the creation of " << max << " connections with connection lost at " << (max + 1) << "... " << flush; @@ -63,12 +69,18 @@ testCreateConnectionsWithMax(TestIntfPrx p, int max) { connection->close().get(); } + + if (postCloseDelay) + { + postCloseDelay(); + } + cout << "ok" << endl; } // Verify that we can create max connections, then connection lost, then recover. void -testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max) +testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max, function postCloseDelay) { cout << "testing the creation of " << max << " connections with connection lost at " << (max + 1) << " then recovery... " << flush; @@ -96,6 +108,11 @@ testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max) connectionList.front()->close().get(); connectionList.erase(connectionList.begin()); + if (postCloseDelay) + { + postCloseDelay(); + } + // Try again try { @@ -114,6 +131,11 @@ testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max) { connection->close().get(); } + + if (postCloseDelay) + { + postCloseDelay(); + } cout << "ok" << endl; } @@ -127,9 +149,19 @@ allTests(TestHelper* helper) string proxyStringMax10 = "test: " + helper->getTestEndpoint(1); TestIntfPrx pMax10(communicator, proxyStringMax10); - testCreateConnections(p, 100); - testCreateConnectionsWithMax(pMax10, 10); - testCreateConnectionsWithMaxAndRecovery(pMax10, 10); + string transport = helper->getTestProtocol(); + + // When the transport is WS or WSS, we need to wait a little bit: the server closes the connection after it + // gets a transport frame from the client. + function postCloseDelay; + if (transport.find("ws") == 0) + { + postCloseDelay = []() { this_thread::sleep_for(50ms); }; + } + + testCreateConnections(p, 100, postCloseDelay); + testCreateConnectionsWithMax(pMax10, 10, postCloseDelay); + testCreateConnectionsWithMaxAndRecovery(pMax10, 10, postCloseDelay); p->shutdown(); } diff --git a/cpp/test/Ice/maxConnections/Client.cpp b/cpp/test/Ice/maxConnections/Client.cpp index 07d85a00953..bd965bb6ef9 100644 --- a/cpp/test/Ice/maxConnections/Client.cpp +++ b/cpp/test/Ice/maxConnections/Client.cpp @@ -16,7 +16,11 @@ class Client : public Test::TestHelper void Client::run(int argc, char** argv) { - Ice::CommunicatorHolder communicator = initialize(argc, argv); + auto properties = createTestProperties(argc, argv); + // We disable retries to make the logs clearer and avoid hiding potential issues. + properties->setProperty("Ice.RetryIntervals", "-1"); + + Ice::CommunicatorHolder communicator = initialize(argc, argv, properties); void allTests(Test::TestHelper*); allTests(this); diff --git a/csharp/test/Ice/maxConnections/AllTests.cs b/csharp/test/Ice/maxConnections/AllTests.cs index c96c540364c..0cc1acd163a 100644 --- a/csharp/test/Ice/maxConnections/AllTests.cs +++ b/csharp/test/Ice/maxConnections/AllTests.cs @@ -15,15 +15,27 @@ internal static async Task allTests(global::Test.TestHelper helper) string proxyStringMax10 = $"test: {helper.getTestEndpoint(1)}"; Test.TestIntfPrx pMax10 = Test.TestIntfPrxHelper.createProxy(communicator, proxyStringMax10); - await testCreateConnections(p, 100, helper.getWriter()); - await testCreateConnectionsWithMax(pMax10, 10, helper.getWriter()); - await testCreateConnectionsWithMaxAndRecovery(pMax10, 10, helper.getWriter()); + // When the transport is WS or WSS, we need to wait a little bit: the server closes the connection after it + // gets a transport frame from the client. + Func? postCloseDelay = null; + if (helper.getTestProtocol().StartsWith("ws")) + { + postCloseDelay = () => Task.Delay(TimeSpan.FromMilliseconds(50)); + } + + await testCreateConnections(p, 100, helper.getWriter(), postCloseDelay); + await testCreateConnectionsWithMax(pMax10, 10, helper.getWriter(), postCloseDelay); + await testCreateConnectionsWithMaxAndRecovery(pMax10, 10, helper.getWriter(), postCloseDelay); await p.shutdownAsync(); } // Verify that we can create connectionCount connections and send a ping on each connection. - private static async Task testCreateConnections(Test.TestIntfPrx p, int connectionCount, TextWriter output) + private static async Task testCreateConnections( + Test.TestIntfPrx p, + int connectionCount, + TextWriter output, + Func? postCloseDelay) { output.Write($"testing the creation of {connectionCount} connections... "); output.Flush(); @@ -38,11 +50,20 @@ private static async Task testCreateConnections(Test.TestIntfPrx p, int connecti // Close all connections await Task.WhenAll(connectionList.Select(c => c.closeAsync())); + + if (postCloseDelay is not null) + { + await postCloseDelay(); + } output.WriteLine("ok"); } // Verify that we can create max connections but not more. - private static async Task testCreateConnectionsWithMax(Test.TestIntfPrx p, int max, TextWriter output) + private static async Task testCreateConnectionsWithMax( + Test.TestIntfPrx p, + int max, + TextWriter output, + Func? postCloseDelay) { output.Write($"testing the creation of {max} connections with connection lost at {max + 1}... "); output.Flush(); @@ -68,11 +89,20 @@ private static async Task testCreateConnectionsWithMax(Test.TestIntfPrx p, int m // Close all connections await Task.WhenAll(connectionList.Select(c => c.closeAsync())); + + if (postCloseDelay is not null) + { + await postCloseDelay(); + } output.WriteLine("ok"); } // Verify that we can create max connections, then connection lost, then recover. - private static async Task testCreateConnectionsWithMaxAndRecovery(Test.TestIntfPrx p, int max, TextWriter output) + private static async Task testCreateConnectionsWithMaxAndRecovery( + Test.TestIntfPrx p, + int max, + TextWriter output, + Func? postCloseDelay) { output.Write($"testing the creation of {max} connections with connection lost at {max + 1} then recovery... "); output.Flush(); @@ -100,12 +130,22 @@ private static async Task testCreateConnectionsWithMaxAndRecovery(Test.TestIntfP await connectionList[0].closeAsync(); connectionList.RemoveAt(0); + if (postCloseDelay is not null) + { + await postCloseDelay(); + } + // Try again await p.ice_pingAsync(); connectionList.Add(p.ice_getCachedConnection()!); // Close all connections await Task.WhenAll(connectionList.Select(c => c.closeAsync())); + + if (postCloseDelay is not null) + { + await postCloseDelay(); + } output.WriteLine("ok"); } } diff --git a/csharp/test/Ice/maxConnections/Client.cs b/csharp/test/Ice/maxConnections/Client.cs index d5ec550f711..85de82f9844 100644 --- a/csharp/test/Ice/maxConnections/Client.cs +++ b/csharp/test/Ice/maxConnections/Client.cs @@ -8,7 +8,11 @@ public class Client : global::Test.TestHelper { public override async Task runAsync(string[] args) { - using var communicator = initialize(ref args); + Properties properties = createTestProperties(ref args); + // We disable retries to make the logs clearer and avoid hiding potential issues. + properties.setProperty("Ice.RetryIntervals", "-1"); + + using var communicator = initialize(properties); await AllTests.allTests(this); } diff --git a/java/test/src/main/java/test/Ice/maxConnections/AllTests.java b/java/test/src/main/java/test/Ice/maxConnections/AllTests.java index b22cbed20b2..f1510f94299 100644 --- a/java/test/src/main/java/test/Ice/maxConnections/AllTests.java +++ b/java/test/src/main/java/test/Ice/maxConnections/AllTests.java @@ -16,16 +16,27 @@ static void allTests(test.TestHelper helper) { String proxyStringMax10 = "test: " + helper.getTestEndpoint(1); var pMax10 = TestIntfPrx.createProxy(communicator, proxyStringMax10); - testCreateConnections(p, 100, helper.getWriter()); - testCreateConnectionsWithMax(pMax10, 10, helper.getWriter()); - testCreateConnectionsWithMaxAndRecovery(pMax10, 10, helper.getWriter()); + Runnable postCloseDelay = null; + // When the transport is WS or WSS, we need to wait a little bit: the server closes + // the connection after it gets a transport frame from the client. + if (helper.getTestProtocol().startsWith("ws")) { + try { + Thread.sleep(50); + } catch (InterruptedException ex) { + // ignore + } + } + + testCreateConnections(p, 100, helper.getWriter(), postCloseDelay); + testCreateConnectionsWithMax(pMax10, 10, helper.getWriter(), postCloseDelay); + testCreateConnectionsWithMaxAndRecovery(pMax10, 10, helper.getWriter(), postCloseDelay); p.shutdown(); } // Verify that we can create connectionCount connections and send a ping on each connection. private static void testCreateConnections( - TestIntfPrx p, int connectionCount, PrintWriter output) { + TestIntfPrx p, int connectionCount, PrintWriter output, Runnable postCloseDelay) { output.write("testing the creation of " + connectionCount + " connections... "); output.flush(); @@ -41,11 +52,16 @@ private static void testCreateConnections( connectionList.get(i).close(); } + if (postCloseDelay != null) { + postCloseDelay.run(); + } + output.println("ok"); } // Verify that we can create max connections but not more. - private static void testCreateConnectionsWithMax(TestIntfPrx p, int max, PrintWriter output) { + private static void testCreateConnectionsWithMax( + TestIntfPrx p, int max, PrintWriter output, Runnable postCloseDelay) { output.write( "testing the creation of " + max @@ -74,12 +90,16 @@ private static void testCreateConnectionsWithMax(TestIntfPrx p, int max, PrintWr connectionList.get(i).close(); } + if (postCloseDelay != null) { + postCloseDelay.run(); + } + output.println("ok"); } // Verify that we can create max connections, then connection lost, then recover. private static void testCreateConnectionsWithMaxAndRecovery( - TestIntfPrx p, int max, PrintWriter output) { + TestIntfPrx p, int max, PrintWriter output, Runnable postCloseDelay) { output.write( "testing the creation of " + max @@ -107,6 +127,10 @@ private static void testCreateConnectionsWithMaxAndRecovery( connectionList.get(0).close(); connectionList.remove(0); + if (postCloseDelay != null) { + postCloseDelay.run(); + } + // Try again p.ice_ping(); connectionList.add(p.ice_getCachedConnection()); @@ -116,6 +140,10 @@ private static void testCreateConnectionsWithMaxAndRecovery( connectionList.get(i).close(); } + if (postCloseDelay != null) { + postCloseDelay.run(); + } + output.println("ok"); } diff --git a/java/test/src/main/java/test/Ice/maxConnections/Client.java b/java/test/src/main/java/test/Ice/maxConnections/Client.java index 7918b8a058a..3ec2e2a6ac4 100644 --- a/java/test/src/main/java/test/Ice/maxConnections/Client.java +++ b/java/test/src/main/java/test/Ice/maxConnections/Client.java @@ -8,6 +8,9 @@ public void run(String[] args) { var properties = createTestProperties(args); properties.setProperty("Ice.Package.Test", "test.Ice.maxConnections"); + // We disable retries to make the logs clearer and avoid hiding potential issues. + properties.setProperty("Ice.RetryIntervals", "-1"); + try (var communicator = initialize(properties)) { AllTests.allTests(this); }