diff options
Diffstat (limited to 'cpp/test/Ice/adapterDeactivation/AllTests.cpp')
-rw-r--r-- | cpp/test/Ice/adapterDeactivation/AllTests.cpp | 58 |
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; } |