Skip to content

Commit

Permalink
Add test for IdleTimeout = 0 (#3163)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Nov 18, 2024
1 parent 7353f68 commit d3d0d1f
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 4 deletions.
21 changes: 21 additions & 0 deletions cpp/test/Ice/idleTimeout/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ testEnableDisableIdleCheck(bool enabled, const string& proxyString, const Proper
cout << "ok" << endl;
}

void
testNoIdleTimeout(const string& proxyString, const PropertiesPtr& properties)
{
cout << "testing connection with idle timeout set to 0... " << flush;

// Create a new communicator with the desired properties.
Ice::InitializationData initData;
initData.properties = properties->clone();
initData.properties->setProperty("Ice.Connection.Client.IdleTimeout", "0");
Ice::CommunicatorHolder holder = initialize(initData);
TestIntfPrx p(holder.communicator(), proxyString);

ConnectionPtr connection = p->ice_getConnection();
test(connection);
p->sleep(2000); // the implementation in the server sleeps for 2,000ms
connection->close().get();
cout << "ok" << endl;
}

void
allTests(TestHelper* helper)
{
Expand All @@ -98,11 +117,13 @@ allTests(TestHelper* helper)

string proxyStringDefaultMax = "test: " + helper->getTestEndpoint(1);
string proxyString3s = "test: " + helper->getTestEndpoint(2);
string proxyStringNoIdleTimeout = "test: " + helper->getTestEndpoint(3);

testIdleCheckDoesNotAbortBackPressuredConnection(p);
testConnectionAbortedByIdleCheck(proxyStringDefaultMax, communicator->getProperties());
testEnableDisableIdleCheck(true, proxyString3s, communicator->getProperties());
testEnableDisableIdleCheck(false, proxyString3s, communicator->getProperties());
testNoIdleTimeout(proxyStringNoIdleTimeout, communicator->getProperties());

p->shutdown();
}
10 changes: 8 additions & 2 deletions cpp/test/Ice/idleTimeout/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ Server::run(int argc, char** argv)
adapter->add(std::make_shared<TestIntfI>(), Ice::stringToIdentity("test"));
adapter->activate();

communicator->getProperties()->setProperty("TestAdapterNoIdleTimeout.Endpoints", getTestEndpoint(3));
communicator->getProperties()->setProperty("TestAdapterNoIdleTimeout.Connection.IdleTimeout", "0");
adapter = communicator->createObjectAdapter("TestAdapterNoIdleTimeout");
adapter->add(std::make_shared<TestIntfI>(), Ice::stringToIdentity("test"));
adapter->activate();

// Used by the JavaScript tests
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck.Endpoints", getTestEndpoint(3));
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck.Endpoints", getTestEndpoint(4));
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck.Connection.IdleTimeout", "1");
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck.Connection.EnableIdleCheck", "0");
adapter = communicator->createObjectAdapter("TestAdapterNoIdleCheck");
Expand All @@ -51,7 +57,7 @@ Server::run(int argc, char** argv)
adapter->activate();

// Used by the JavaScript tests
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck3s.Endpoints", getTestEndpoint(4));
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck3s.Endpoints", getTestEndpoint(5));
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck3s.Connection.IdleTimeout", "3");
communicator->getProperties()->setProperty("TestAdapterNoIdleCheck3s.Connection.EnableIdleCheck", "0");
adapter = communicator->createObjectAdapter("TestAdapterNoIdleCheck3s");
Expand Down
22 changes: 22 additions & 0 deletions csharp/test/Ice/idleTimeout/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ internal static async Task allTests(global::Test.TestHelper helper)

string proxyStringDefaultMax = $"test: {helper.getTestEndpoint(1)}";
string proxyString3s = $"test: {helper.getTestEndpoint(2)}";
string proxyStringNoIdleTimeout = $"test: {helper.getTestEndpoint(3)}";

await testIdleCheckDoesNotAbortBackPressuredConnection(p, helper.getWriter());
await testConnectionAbortedByIdleCheck(proxyStringDefaultMax, communicator.getProperties(), helper.getWriter());
await testEnableDisableIdleCheck(true, proxyString3s, communicator.getProperties(), helper.getWriter());
await testEnableDisableIdleCheck(false, proxyString3s, communicator.getProperties(), helper.getWriter());
await testNoIdleTimeout(proxyStringNoIdleTimeout, communicator.getProperties(), helper.getWriter());

await p.shutdownAsync();
}
Expand Down Expand Up @@ -114,4 +116,24 @@ private static async Task testEnableDisableIdleCheck(
}
output.WriteLine("ok");
}

// Verifies the idle check is disabled when the idle timeout is set to 0.
private static async Task testNoIdleTimeout(string proxyString, Properties properties, TextWriter output)
{
output.Write("testing connection with idle timeout set to 0... ");
output.Flush();

// Create a new communicator with the desired properties.
properties = properties.Clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "0");
Communicator communicator = Util.initialize(new InitializationData { properties = properties });
Test.TestIntfPrx p = Test.TestIntfPrxHelper.createProxy(communicator, proxyString);

Connection? connection = await p.ice_getConnectionAsync();
test(connection is not null);

await p.sleepAsync(2000); // the implementation in the server sleeps for 2,000ms
await connection!.closeAsync();
output.WriteLine("ok");
}
}
6 changes: 6 additions & 0 deletions csharp/test/Ice/idleTimeout/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public override void run(string[] args)
adapter3s.add(new TestIntfI(), Ice.Util.stringToIdentity("test"));
adapter3s.activate();

communicator.getProperties().setProperty("TestAdapterNoIdleTimeout.Endpoints", getTestEndpoint(3));
communicator.getProperties().setProperty("TestAdapterNoIdleTimeout.Connection.IdleTimeout", "0");
var adapterNoIdleTimeout = communicator.createObjectAdapter("TestAdapterNoIdleTimeout");
adapterNoIdleTimeout.add(new TestIntfI(), Ice.Util.stringToIdentity("test"));
adapterNoIdleTimeout.activate();

serverReady();
communicator.waitForShutdown();
}
Expand Down
25 changes: 25 additions & 0 deletions java/test/src/main/java/test/Ice/idleTimeout/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void allTests(test.TestHelper helper) {

String proxyStringDefaultMax = "test: " + helper.getTestEndpoint(1);
String proxyString3s = "test: " + helper.getTestEndpoint(2);
String proxyStringNoIdleTimeout = "test: " + helper.getTestEndpoint(3);

testIdleCheckDoesNotAbortBackPressuredConnection(p, helper.getWriter());
testConnectionAbortedByIdleCheck(
Expand All @@ -29,6 +30,9 @@ static void allTests(test.TestHelper helper) {
true, proxyString3s, communicator.getProperties(), helper.getWriter());
testEnableDisableIdleCheck(
false, proxyString3s, communicator.getProperties(), helper.getWriter());
testNoIdleTimeout(
proxyStringNoIdleTimeout, communicator.getProperties(), helper.getWriter());

p.shutdown();
}

Expand Down Expand Up @@ -124,6 +128,27 @@ private static void testEnableDisableIdleCheck(
}
}

// Verifies the idle check is disabled when the idle timeout is set to 0.
private static void testNoIdleTimeout(
String proxyString, Properties properties, PrintWriter output) {
output.write("testing connection with idle timeout set to 0... ");
output.flush();

// Create a new communicator with the desired properties.
properties = properties._clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "0");
var initData = new InitializationData();
initData.properties = properties;
try (var communicator = Util.initialize(initData)) {
var p = TestIntfPrx.createProxy(communicator, proxyString);
var connection = p.ice_getConnection();
test(connection != null);
p.sleep(2000); // the implementation in the server sleeps for 2,000ms
connection.close();
}
output.println("ok");
}

private static void test(boolean b) {
if (!b) {
throw new RuntimeException();
Expand Down
10 changes: 10 additions & 0 deletions java/test/src/main/java/test/Ice/idleTimeout/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public void run(String[] args) {
adapter3s.add(new TestIntfI(), new Identity("test", ""));
adapter3s.activate();

communicator
.getProperties()
.setProperty("TestAdapterNoIdleTimeout.Endpoints", getTestEndpoint(3));
communicator
.getProperties()
.setProperty("TestAdapterNoIdleTimeout.Connection.IdleTimeout", "0");
var adapterNoIdleTimeout = communicator.createObjectAdapter("TestAdapterNoIdleTimeout");
adapterNoIdleTimeout.add(new TestIntfI(), new Identity("test", ""));
adapterNoIdleTimeout.activate();

serverReady();
communicator.waitForShutdown();
}
Expand Down
31 changes: 29 additions & 2 deletions js/test/Ice/idleTimeout/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function testConnectionNotAbortedByIdleCheck(properties: Ice.Properties, h
output.write("testing connection not aborted by idle check... ");

// The server has 1s idle timeout, and disabled idle check.
const proxyString = `test-bidir: ${helper.getTestEndpoint(3)}`;
const proxyString = `test-bidir: ${helper.getTestEndpoint(4)}`;

const completedPromise = new Ice.Promise<void>();

Expand Down Expand Up @@ -67,7 +67,7 @@ async function testConnectionAbortedByIdleCheck(properties: Ice.Properties, help
output.write("testing connection aborted by idle check... ");

// The server has 3s idle timeout, and disabled idle check.
const proxyString = `test-bidir: ${helper.getTestEndpoint(4)}`;
const proxyString = `test-bidir: ${helper.getTestEndpoint(5)}`;

const completedPromise = new Ice.Promise<void>();

Expand Down Expand Up @@ -145,6 +145,31 @@ async function testServerWithEnableDisableIdleCheck(
output.writeLine("ok");
}

// Verifies the idle check is disabled when the idle timeout is set to 0.
async function testNoIdleTimeout(properties: Ice.Properties, helper: TestHelper): Promise<void> {
const output = helper.getWriter();
output.write(`testing connection with idle timeout set to 0... `);

const proxyStringNoIdleTimeout = `test: ${helper.getTestEndpoint(3)}`;

// Create a new communicator with the desired properties.
properties = properties.clone();
properties.setProperty("Ice.Connection.Client.IdleTimeout", "0");
const initData = new Ice.InitializationData();
initData.properties = properties;
const communicator = Ice.initialize(initData);
const p = new Test.TestIntfPrx(communicator, proxyStringNoIdleTimeout);
try {
const connection = await p.ice_getConnection();
test(connection != null);
await p.sleep(2000); // the implementation in the server sleeps for 2,000ms
await connection.close();
} finally {
await communicator.destroy();
}
output.writeLine("ok");
}

export class Client extends TestHelper {
async allTests(): Promise<void> {
const communicator = this.communicator();
Expand All @@ -155,6 +180,8 @@ export class Client extends TestHelper {
await testServerWithEnableDisableIdleCheck(true, communicator.getProperties(), this);
await testServerWithEnableDisableIdleCheck(false, communicator.getProperties(), this);

await testNoIdleTimeout(communicator.getProperties(), this);

const p = Test.TestIntfPrx.uncheckedCast(communicator.stringToProxy(`test: ${this.getTestEndpoint(0)}`));
await p.shutdown();
}
Expand Down

0 comments on commit d3d0d1f

Please sign in to comment.