Skip to content

Commit

Permalink
Ice.ServerIdleTime test fixes (#2041)
Browse files Browse the repository at this point in the history
- Remove the random usage in the tests
- Adds a test to exercise Ice.ServerIdleTime
- Fix a few selector bugs

Closes #2025
  • Loading branch information
externl authored Apr 11, 2024
1 parent 1061d69 commit 05fbaef
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- os: macos-14
language: cpp
name: "xcodesdk"
make_flags: "CONFIGS=xcodesdk PLATFORMS='iphonesimulator'"
make_flags: "CONFIGS=xcodesdk PLATFORMS=iphonesimulator"
test_flags: "--config=xcodesdk --platform=iphonesimulator --controller-app"

- os: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions cpp/src/Ice/Selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ Selector::select(int timeout)
}
else if (timeout > 0)
{
// kpoll and select use seconds, epoll and poll use milliseconds
# if !defined(ICE_USE_KQUEUE) && !defined(ICE_USE_SELECT)
timeout = timeout * 1000;
# endif
}
else
{
Expand All @@ -655,24 +658,20 @@ Selector::select(int timeout)
assert(!_events.empty());
if (timeout >= 0)
{
struct timespec ts;
ts.tv_sec = timeout;
ts.tv_nsec = 0;
_count = kevent(_queueFd, 0, 0, &_events[0], static_cast<int>(_events.size()), &ts);
timespec ts{.tv_sec = timeout, .tv_nsec = 0};
_count = kevent(_queueFd, nullptr, 0, &_events[0], static_cast<int>(_events.size()), &ts);
}
else
{
_count = kevent(_queueFd, 0, 0, &_events[0], static_cast<int>(_events.size()), 0);
_count = kevent(_queueFd, nullptr, 0, &_events[0], static_cast<int>(_events.size()), nullptr);
}
# elif defined(ICE_USE_SELECT)
fd_set* rFdSet = fdSetCopy(_selectedReadFdSet, _readFdSet);
fd_set* wFdSet = fdSetCopy(_selectedWriteFdSet, _writeFdSet);
fd_set* eFdSet = fdSetCopy(_selectedErrorFdSet, _errorFdSet);
if (timeout >= 0)
{
struct timeval tv;
tv.tv_sec = timeout;
tv.tv_usec = 0;
timespec ts{.tv_sec = timeout, .tv_nsec = 0};
_count = ::select(0, rFdSet, wFdSet, eFdSet, &tv); // The first parameter is ignored on Windows
}
else
Expand Down Expand Up @@ -1394,6 +1393,7 @@ Selector::select(int timeout)
{
break;
}
throw SelectorTimeoutException();
}
else
{
Expand Down
17 changes: 17 additions & 0 deletions cpp/test/Ice/adapterDeactivation/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,21 @@ allTests(Test::TestHelper* helper)
{
cout << "ok" << endl;
}
cout << "testing server idle time..." << flush;
{
InitializationData idleInitData;
idleInitData.properties = communicator->getProperties()->clone();
idleInitData.properties->setProperty("Ice.ServerIdleTime", "1");
#ifdef _WIN32
// With our Windows implementation, the thread pool threads have to be idle first before server idle time is
// checked
idleInitData.properties->setProperty("Ice.ThreadPool.Server.ThreadIdleTime", "1");
#endif
CommunicatorHolder idleCommunicator(idleInitData);
// The server thread pool is started lazily so we need to create an object adapter and activate it.
ObjectAdapterPtr idleOA = idleCommunicator->createObjectAdapterWithEndpoints("IdleOA", "tcp -h 127.0.0.1");
idleOA->activate();
idleCommunicator->waitForShutdown();
}
cout << "ok" << endl;
}
10 changes: 1 addition & 9 deletions cpp/test/Ice/faultTolerance/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ class Server : public Test::TestHelper
void
Server::run(int argc, char** argv)
{
//
// In this test, we need a longer server idle time, otherwise
// our test servers may time out before they are used in the
// test.
//
Ice::PropertiesPtr properties = createTestProperties(argc, argv);
properties->setProperty("Ice.ServerIdleTime", "120"); // Two minutes.

Ice::CommunicatorHolder communicator = initialize(argc, argv, properties);
Ice::CommunicatorHolder communicator = initialize(argc, argv);

int port = 0;
for (int i = 1; i < argc; ++i)
Expand Down
15 changes: 5 additions & 10 deletions cpp/test/IceGrid/activation/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
<parameter name="activation-delay" default="0"/>
<parameter name="deactivation-delay" default="0"/>
<parameter name="fail-on-startup" default="0"/>
<server id="${id}" exe="${server.dir}/server"
activation="${activation}"
activation-timeout="${activation-timeout}"
deactivation-timeout="${deactivation-timeout}">
<server id="${id}" exe="${server.dir}/server" activation="${activation}" activation-timeout="${activation-timeout}" deactivation-timeout="${deactivation-timeout}">
<adapter name="TestAdapter" endpoints="default">
<object identity="${server}" type="Test"/>
<allocatable identity="${server}" type="Test"/>
Expand All @@ -32,8 +29,7 @@
<property name="IceGrid.Node.Endpoints" value="default"/>
<property name="IceGrid.Node.Name" value="${server}"/>
<property name="IceGrid.Node.Data" value="${server.data}"/>
<property name="IceGrid.Node.PropertiesOverride"
value="${properties-override} Ice.ServerIdleTime=0 Ice.PrintProcessId=0 Ice.PrintAdapterReady=0"/>
<property name="IceGrid.Node.PropertiesOverride" value="${properties-override} Ice.PrintProcessId=0 Ice.PrintAdapterReady=0"/>
<property name="IceGrid.Node.DisableOnFailure" value="${disable-on-failure}"/>
</server>
</server-template>
Expand All @@ -47,8 +43,7 @@
<server-instance template="Server" id="server-always" activation="always"/>
<server-instance template="Server" id="server-session" activation="session"/>
<server-instance template="Server" id="server-activation-timeout" activation-delay="5" activation-timeout="3"/>
<server-instance template="Server" id="server-deactivation-timeout" deactivation-delay="60"
deactivation-timeout="3"/>
<server-instance template="Server" id="server-deactivation-timeout" deactivation-delay="60" deactivation-timeout="3"/>
<server-instance template="Server" id="fail-on-startup" fail-on-startup="1"/>

<server id="invalid-exe" exe="server2" activation="on-demand">
Expand All @@ -58,8 +53,8 @@
</server>
<server id="invalid-pwd" exe="./server" pwd="./bogus">
<adapter name="TestAdapter" endpoints="default">
<object identity="${server}" type="Test"/>
</adapter>
<object identity="${server}" type="Test"/>
</adapter>
</server>
<server id="invalid-exe-no-oa" exe="./server2">
<property name="Ice.Admin.Endpoints" value=""/>
Expand Down
3 changes: 1 addition & 2 deletions cpp/test/IceGrid/replication/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<property name="IceGrid.InstanceName" value="RepTestIceGrid"/>
<property name="IceGrid.Node.Name" value="${server}"/>
<property name="IceGrid.Node.Data" value="${server.data}"/>
<property name="IceGrid.Node.PropertiesOverride"
value="${properties-override} Ice.ServerIdleTime=0 Ice.PrintProcessId=0 Ice.PrintAdapterReady=0"/>
<property name="IceGrid.Node.PropertiesOverride" value="${properties-override} Ice.PrintProcessId=0 Ice.PrintAdapterReady=0"/>
<property name="Ice.Default.Locator" value="RepTestIceGrid/Locator:default -p 12050:default -p 12051:default -p 12052"/>
<property name="IceGrid.Node.Trace.Replica" value="1"/>
<property name="IceGrid.Node.Trace.Adapter" value="1"/>
Expand Down
17 changes: 17 additions & 0 deletions csharp/test/Ice/adapterDeactivation/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ public class AllTests : global::Test.AllTests
output.WriteLine("ok");
}

output.Write("testing server idle time...");
output.Flush();
{
Ice.InitializationData initData = new Ice.InitializationData()
{
properties = communicator.getProperties().ice_clone_(),
};
initData.properties.setProperty("Ice.ServerIdleTime", "1");
// The thread pool threads have to be idle first before server idle time is checked.
initData.properties.setProperty("Ice.ThreadPool.Server.ThreadIdleTime", "1");
using Ice.Communicator idleCommunicator = Ice.Util.initialize(initData);
ObjectAdapter idleOA = idleCommunicator.createObjectAdapterWithEndpoints("IdleAdapter", "tcp -h 127.0.0.1 ");
idleOA.activate();
idleCommunicator.waitForShutdown();
}
output.WriteLine("ok");

return obj;
}
}
Expand Down
4 changes: 1 addition & 3 deletions csharp/test/Ice/binding/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public class Server : TestHelper
{
public override void run(string[] args)
{
Ice.Properties properties = createTestProperties(ref args);
properties.setProperty("Ice.ServerIdleTime", "30");
using (var communicator = initialize(properties))
using (var communicator = initialize(ref args))
{
communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter");
Expand Down
1 change: 0 additions & 1 deletion csharp/test/Ice/dispatcher/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public override void run(string[] args)
{
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = createTestProperties(ref args);
initData.properties.setProperty("Ice.ServerIdleTime", "30");
//
// Limit the recv buffer size, this test relies on the socket
// send() blocking after sending a given amount of data.
Expand Down
4 changes: 1 addition & 3 deletions csharp/test/Ice/enums/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public class Server : TestHelper
{
public override void run(string[] args)
{
Ice.Properties properties = createTestProperties(ref args);
properties.setProperty("Ice.ServerIdleTime", "30");
using (var communicator = initialize(properties))
using (var communicator = initialize(ref args))
{
communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter");
Expand Down
1 change: 0 additions & 1 deletion csharp/test/Ice/faultTolerance/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class Server : Test.TestHelper
public override void run(string[] args)
{
Ice.Properties properties = createTestProperties(ref args);
properties.setProperty("Ice.ServerIdleTime", "120");
int port = 0;
for (int i = 0; i < args.Length; i++)
{
Expand Down
15 changes: 15 additions & 0 deletions java/test/src/main/java/test/Ice/adapterDeactivation/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ public static TestIntfPrx allTests(test.TestHelper helper) {
out.flush();
}

out.print("testing server idle time...");
out.flush();
{
com.zeroc.Ice.InitializationData initData = new com.zeroc.Ice.InitializationData();
initData.properties = communicator.getProperties()._clone();
initData.properties.setProperty("Ice.ServerIdleTime", "1");
try (com.zeroc.Ice.Communicator idleCommunicator = com.zeroc.Ice.Util.initialize(initData)) {
com.zeroc.Ice.ObjectAdapter adapter =
idleCommunicator.createObjectAdapterWithEndpoints("IdleAdapter", "tcp -h 127.0.0.1");
adapter.activate();
idleCommunicator.waitForShutdown();
}
}
out.println("ok");

return obj;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public void run(String[] args) {
java.util.List<String> remainingArgs = new java.util.ArrayList<String>();
com.zeroc.Ice.Properties properties = createTestProperties(args, remainingArgs);
properties.setProperty("Ice.Package.Test", "test.Ice.faultTolerance");
properties.setProperty("Ice.ServerIdleTime", "120");
try (com.zeroc.Ice.Communicator communicator = initialize(properties)) {
int port = 0;
PrintWriter out = getWriter();
Expand Down
7 changes: 0 additions & 7 deletions python/test/Ice/faultTolerance/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ def pid(self, current=None):
class Server(TestHelper):
def run(self, args):
properties = self.createTestProperties(args)
#
# In this test, we need a longer server idle time, otherwise
# our test servers may time out before they are used in the
# test.
#
properties.setProperty("Ice.ServerIdleTime", "120") # Two minutes.

port = 0
for arg in args:
if arg[0] == "-":
Expand Down
3 changes: 0 additions & 3 deletions swift/test/Ice/binding/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import TestCommon

class Server: TestHelperI {
override public func run(args: [String]) throws {
let properties = try createTestProperties(args)
properties.setProperty(key: "Ice.ServerIdleTime", value: "30")

let communicator = try initialize(args)
defer {
communicator.destroy()
Expand Down

0 comments on commit 05fbaef

Please sign in to comment.