Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delay after closing WS connection #2886

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions cpp/test/Ice/maxConnections/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void()> postCloseDelay)
{
cout << "testing the creation of " << connectionCount << " connections... " << flush;
vector<ConnectionPtr> connectionList;
Expand All @@ -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<void()> postCloseDelay)
{
cout << "testing the creation of " << max << " connections with connection lost at " << (max + 1) << "... "
<< flush;
Expand Down Expand Up @@ -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<void()> postCloseDelay)
{
cout << "testing the creation of " << max << " connections with connection lost at " << (max + 1)
<< " then recovery... " << flush;
Expand Down Expand Up @@ -96,6 +108,11 @@ testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max)
connectionList.front()->close().get();
connectionList.erase(connectionList.begin());

if (postCloseDelay)
{
postCloseDelay();
}

// Try again
try
{
Expand All @@ -114,6 +131,11 @@ testCreateConnectionsWithMaxAndRecovery(TestIntfPrx p, int max)
{
connection->close().get();
}

if (postCloseDelay)
{
postCloseDelay();
}
cout << "ok" << endl;
}

Expand All @@ -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<void()> 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();
}
6 changes: 5 additions & 1 deletion cpp/test/Ice/maxConnections/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 46 additions & 6 deletions csharp/test/Ice/maxConnections/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task>? 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<Task>? postCloseDelay)
{
output.Write($"testing the creation of {connectionCount} connections... ");
output.Flush();
Expand All @@ -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<Task>? postCloseDelay)
{
output.Write($"testing the creation of {max} connections with connection lost at {max + 1}... ");
output.Flush();
Expand All @@ -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<Task>? postCloseDelay)
{
output.Write($"testing the creation of {max} connections with connection lost at {max + 1} then recovery... ");
output.Flush();
Expand Down Expand Up @@ -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");
}
}
6 changes: 5 additions & 1 deletion csharp/test/Ice/maxConnections/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
40 changes: 34 additions & 6 deletions java/test/src/main/java/test/Ice/maxConnections/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -116,6 +140,10 @@ private static void testCreateConnectionsWithMaxAndRecovery(
connectionList.get(i).close();
}

if (postCloseDelay != null) {
postCloseDelay.run();
}

output.println("ok");
}

Expand Down
3 changes: 3 additions & 0 deletions java/test/src/main/java/test/Ice/maxConnections/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading