Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ice.ServerIdleTime test fixes
Browse files Browse the repository at this point in the history
externl committed Apr 10, 2024

Verified

This commit was signed with the committer’s verified signature.
broonie Mark Brown
1 parent 9998652 commit 7bd053c
Showing 14 changed files with 65 additions and 42 deletions.
15 changes: 7 additions & 8 deletions cpp/src/Ice/Selector.cpp
Original file line number Diff line number Diff line change
@@ -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
{
@@ -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
18 changes: 18 additions & 0 deletions cpp/test/Ice/adapterDeactivation/AllTests.cpp
Original file line number Diff line number Diff line change
@@ -184,4 +184,22 @@ allTests(Test::TestHelper* helper)
{
cout << "ok" << endl;
}
cout << "testing idle server deactivation..." << flush;
{
InitializationData 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
initData.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;
}
7 changes: 0 additions & 7 deletions cpp/test/Ice/faultTolerance/Server.cpp
Original file line number Diff line number Diff line change
@@ -19,14 +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);

int port = 0;
15 changes: 5 additions & 10 deletions cpp/test/IceGrid/activation/application.xml
Original file line number Diff line number Diff line change
@@ -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"/>
@@ -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>
@@ -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">
@@ -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=""/>
3 changes: 1 addition & 2 deletions cpp/test/IceGrid/replication/application.xml
Original file line number Diff line number Diff line change
@@ -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"/>
19 changes: 19 additions & 0 deletions csharp/test/Ice/adapterDeactivation/AllTests.cs
Original file line number Diff line number Diff line change
@@ -197,6 +197,25 @@ public class AllTests : global::Test.AllTests
output.WriteLine("ok");
}

output.Write("testing idle server deactivation... ");
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;
}
}
1 change: 0 additions & 1 deletion csharp/test/Ice/binding/Server.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ 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))
{
communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
1 change: 0 additions & 1 deletion csharp/test/Ice/dispatcher/Server.cs
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion csharp/test/Ice/enums/Server.cs
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ 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))
{
communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0));
1 change: 0 additions & 1 deletion csharp/test/Ice/faultTolerance/Server.cs
Original file line number Diff line number Diff line change
@@ -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++)
{
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
@@ -200,6 +200,21 @@ public static TestIntfPrx allTests(test.TestHelper helper) {
out.flush();
}

out.print("testing idle server deactivation...");
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
@@ -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();
7 changes: 0 additions & 7 deletions python/test/Ice/faultTolerance/Server.py
Original file line number Diff line number Diff line change
@@ -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] == "-":
3 changes: 0 additions & 3 deletions swift/test/Ice/binding/Server.swift
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7bd053c

Please sign in to comment.