summaryrefslogtreecommitdiff
path: root/cpp/test
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2024-07-22 18:32:01 +0200
committerGitHub <noreply@github.com>2024-07-22 18:32:01 +0200
commitcd8dfb03702b4d097a49a45f8cca091b5a14f4db (patch)
tree42c97c3875ef115b7d473359741f4a2cbdb8fd3f /cpp/test
parentRemoved bogus FD limit setting for the binding test (#2520) (diff)
downloadice-cd8dfb03702b4d097a49a45f8cca091b5a14f4db.tar.bz2
ice-cd8dfb03702b4d097a49a45f8cca091b5a14f4db.tar.xz
ice-cd8dfb03702b4d097a49a45f8cca091b5a14f4db.zip
Fixed thread idle time bug (#2537)
This PR fixes a bug introduced with the C# thread pool back pressure fix related to the server/thread idle time. It also adds tests for C++/Java.
Diffstat (limited to 'cpp/test')
-rw-r--r--cpp/test/Ice/adapterDeactivation/AllTests.cpp58
1 files changed, 43 insertions, 15 deletions
diff --git a/cpp/test/Ice/adapterDeactivation/AllTests.cpp b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
index 1a7a46da718..3ff45871b37 100644
--- a/cpp/test/Ice/adapterDeactivation/AllTests.cpp
+++ b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
@@ -6,6 +6,10 @@
#include <TestHelper.h>
#include <Test.h>
+#ifdef ICE_CPP11_MAPPING
+# include <thread>
+#endif
+
using namespace std;
using namespace Ice;
using namespace Test;
@@ -210,23 +214,47 @@ allTests(Test::TestHelper* helper)
cout << "ok" << endl;
}
+#ifdef ICE_CPP11_MAPPING
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();
- }
+ std::thread thread1([]()
+ {
+ InitializationData idleInitData;
+ idleInitData.properties = createProperties();
+ 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();
+ idleCommunicator->destroy();
+ });
+ std::thread thread2([]()
+ {
+ InitializationData idleInitData;
+ idleInitData.properties = createProperties();
+ idleInitData.properties->setProperty("Ice.ServerIdleTime", "0");
+ #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();
+ std::this_thread::sleep_for(1200ms);
+ test(!idleCommunicator->isShutdown());
+ idleCommunicator->destroy();
+ });
+ thread1.join();
+ thread2.join();
cout << "ok" << endl;
+#endif
return obj;
}