summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2017-09-15 12:18:41 +0200
committerBenoit Foucher <benoit@zeroc.com>2017-09-15 12:18:41 +0200
commita4fb9c391caabef6de9cfbd126f4fe10755ece49 (patch)
tree36dfe5b0a110dddd09f49882649d8c2de825f4b4 /cpp
parentRemoved Eclipse .launch files (diff)
downloadice-a4fb9c391caabef6de9cfbd126f4fe10755ece49.tar.bz2
ice-a4fb9c391caabef6de9cfbd126f4fe10755ece49.tar.xz
ice-a4fb9c391caabef6de9cfbd126f4fe10755ece49.zip
Fixed timeout tests to be less time sensitive
The tests now use a controller to hold/activate the adapter instead of relying on a timer. Fixes ICE-8312.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/test/Ice/timeout/AllTests.cpp81
-rw-r--r--cpp/test/Ice/timeout/Client.cpp5
-rw-r--r--cpp/test/Ice/timeout/Server.cpp11
-rw-r--r--cpp/test/Ice/timeout/Test.ice5
-rw-r--r--cpp/test/Ice/timeout/TestI.cpp30
-rw-r--r--cpp/test/Ice/timeout/TestI.h13
6 files changed, 102 insertions, 43 deletions
diff --git a/cpp/test/Ice/timeout/AllTests.cpp b/cpp/test/Ice/timeout/AllTests.cpp
index 4bc13e1df8a..8834e76aed7 100644
--- a/cpp/test/Ice/timeout/AllTests.cpp
+++ b/cpp/test/Ice/timeout/AllTests.cpp
@@ -110,7 +110,7 @@ connect(const Ice::ObjectPrxPtr& prx)
}
-TimeoutPrxPtr
+void
allTests(const Ice::CommunicatorPtr& communicator)
{
string sref = "timeout:" + getTestEndpoint(communicator, 0);
@@ -120,13 +120,17 @@ allTests(const Ice::CommunicatorPtr& communicator)
TimeoutPrxPtr timeout = ICE_CHECKED_CAST(TimeoutPrx, obj);
test(timeout);
+ ControllerPrxPtr controller =
+ ICE_CHECKED_CAST(ControllerPrx, communicator->stringToProxy("controller:" + getTestEndpoint(communicator, 1)));
+ test(controller);
+
cout << "testing connect timeout... " << flush;
{
//
// Expect ConnectTimeoutException.
//
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(100));
- timeout->holdAdapter(500);
+ controller->holdAdapter(-1);
try
{
to->op();
@@ -136,14 +140,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
}
{
//
// Expect success.
//
- timeout->op(); // Ensure adapter is active.
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000));
- timeout->holdAdapter(500);
+ controller->holdAdapter(200);
try
{
to->op();
@@ -165,7 +170,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
//
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(250));
connect(to);
- timeout->holdAdapter(750);
+ controller->holdAdapter(-1);
try
{
to->sendData(seq);
@@ -175,14 +180,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
}
{
//
// Expect success.
//
- timeout->op(); // Ensure adapter is active.
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(1000));
- timeout->holdAdapter(500);
+ controller->holdAdapter(200);
try
{
ByteSeq seq(1000000);
@@ -202,7 +208,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
test(connection == to->ice_getConnection());
try
{
- to->sleep(750);
+ to->sleep(500);
test(false);
}
catch(const Ice::InvocationTimeoutException&)
@@ -228,7 +234,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_invocationTimeout(100));
#ifdef ICE_CPP11_MAPPING
- auto f = to->sleepAsync(750);
+ auto f = to->sleepAsync(500);
try
{
f.get();
@@ -243,7 +249,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
#else
CallbackPtr cb = new Callback();
- to->begin_sleep(750, newCallback_Timeout_sleep(cb, &Callback::responseEx, &Callback::exceptionEx));
+ to->begin_sleep(500, newCallback_Timeout_sleep(cb, &Callback::responseEx, &Callback::exceptionEx));
cb->check();
#endif
obj->ice_ping();
@@ -323,7 +329,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, obj->ice_timeout(250));
Ice::ConnectionPtr connection = connect(to);
- timeout->holdAdapter(600);
+ controller->holdAdapter(-1);
connection->close(Ice::ICE_SCOPED_ENUM(ConnectionClose, GracefullyWithWait));
try
{
@@ -333,17 +339,21 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
test(false);
}
- IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(650));
- try
- {
- connection->getInfo();
- test(false);
- }
- catch(const Ice::ConnectionManuallyClosedException& ex)
+ while(true)
{
- // Expected.
- test(ex.graceful);
+ try
+ {
+ connection->getInfo();
+ IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(10));
+ }
+ catch(const Ice::ConnectionManuallyClosedException& ex)
+ {
+ // Expected.
+ test(ex.graceful);
+ break;
+ }
}
+ controller->resumeAdapter();
timeout->op(); // Ensure adapter is active.
}
cout << "ok" << endl;
@@ -361,7 +371,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
Ice::CommunicatorHolder ich(initData);
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, ich->stringToProxy(sref));
connect(to);
- timeout->holdAdapter(500);
+ controller->holdAdapter(-1);
try
{
to->sendData(seq);
@@ -371,14 +381,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
//
// Calling ice_timeout() should have no effect.
//
- timeout->op(); // Ensure adapter is active.
to = ICE_UNCHECKED_CAST(TimeoutPrx, to->ice_timeout(1000));
connect(to);
- timeout->holdAdapter(500);
+ controller->holdAdapter(-1);
try
{
to->sendData(seq);
@@ -388,6 +399,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
}
{
//
@@ -397,7 +410,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
initData.properties = communicator->getProperties()->clone();
initData.properties->setProperty("Ice.Override.ConnectTimeout", "250");
Ice::CommunicatorHolder ich(initData);
- timeout->holdAdapter(750);
+ controller->holdAdapter(-1);
TimeoutPrxPtr to = ICE_UNCHECKED_CAST(TimeoutPrx, ich->stringToProxy(sref));
try
{
@@ -408,11 +421,13 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
+
//
// Calling ice_timeout() should have no effect on the connect timeout.
//
- timeout->op(); // Ensure adapter is active.
- timeout->holdAdapter(750);
+ controller->holdAdapter(-1);
to = ICE_UNCHECKED_CAST(TimeoutPrx, to->ice_timeout(1000));
try
{
@@ -423,13 +438,15 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
+
//
// Verify that timeout set via ice_timeout() is still used for requests.
//
- timeout->op(); // Ensure adapter is active.
to = ICE_UNCHECKED_CAST(TimeoutPrx, to->ice_timeout(250));
connect(to);
- timeout->holdAdapter(750);
+ controller->holdAdapter(-1);
try
{
to->sendData(seq);
@@ -439,6 +456,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
{
// Expected.
}
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
}
{
//
@@ -449,10 +468,12 @@ allTests(const Ice::CommunicatorPtr& communicator)
initData.properties->setProperty("Ice.Override.CloseTimeout", "100");
Ice::CommunicatorHolder ich(initData);
Ice::ConnectionPtr connection = ich->stringToProxy(sref)->ice_getConnection();
- timeout->holdAdapter(800);
+ controller->holdAdapter(-1);
IceUtil::Time now = IceUtil::Time::now();
ich.release()->destroy();
test(IceUtil::Time::now() - now < IceUtil::Time::milliSeconds(700));
+ controller->resumeAdapter();
+ timeout->op(); // Ensure adapter is active.
}
cout << "ok" << endl;
@@ -548,5 +569,5 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
cout << "ok" << endl;
- return timeout;
+ controller->shutdown();
}
diff --git a/cpp/test/Ice/timeout/Client.cpp b/cpp/test/Ice/timeout/Client.cpp
index 62ddac641b8..fb8d546bd56 100644
--- a/cpp/test/Ice/timeout/Client.cpp
+++ b/cpp/test/Ice/timeout/Client.cpp
@@ -19,9 +19,8 @@ using namespace Test;
int
run(int, char**, const Ice::CommunicatorPtr& communicator)
{
- TimeoutPrxPtr allTests(const Ice::CommunicatorPtr&);
- TimeoutPrxPtr timeout = allTests(communicator);
- timeout->shutdown();
+ void allTests(const Ice::CommunicatorPtr&);
+ allTests(communicator);
return EXIT_SUCCESS;
}
diff --git a/cpp/test/Ice/timeout/Server.cpp b/cpp/test/Ice/timeout/Server.cpp
index 8922a336669..64b08e7cf3c 100644
--- a/cpp/test/Ice/timeout/Server.cpp
+++ b/cpp/test/Ice/timeout/Server.cpp
@@ -19,10 +19,17 @@ int
run(int, char**, const Ice::CommunicatorPtr& communicator)
{
communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint(communicator, 0));
+ communicator->getProperties()->setProperty("ControllerAdapter.Endpoints", getTestEndpoint(communicator, 1));
+ communicator->getProperties()->setProperty("ControllerAdapter.ThreadPool.Size", "1");
+
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter");
- Ice::ObjectPtr object = ICE_MAKE_SHARED(TimeoutI);
- adapter->add(object, Ice::stringToIdentity("timeout"));
+ adapter->add(ICE_MAKE_SHARED(TimeoutI), Ice::stringToIdentity("timeout"));
adapter->activate();
+
+ Ice::ObjectAdapterPtr controllerAdapter = communicator->createObjectAdapter("ControllerAdapter");
+ controllerAdapter->add(ICE_MAKE_SHARED(ControllerI, adapter), Ice::stringToIdentity("controller"));
+ controllerAdapter->activate();
+
TEST_READY
communicator->waitForShutdown();
return EXIT_SUCCESS;
diff --git a/cpp/test/Ice/timeout/Test.ice b/cpp/test/Ice/timeout/Test.ice
index aad831a9993..d611817c1ac 100644
--- a/cpp/test/Ice/timeout/Test.ice
+++ b/cpp/test/Ice/timeout/Test.ice
@@ -19,9 +19,12 @@ interface Timeout
void op();
void sendData(ByteSeq seq);
void sleep(int to);
+}
+interface Controller
+{
void holdAdapter(int to);
-
+ void resumeAdapter();
void shutdown();
}
diff --git a/cpp/test/Ice/timeout/TestI.cpp b/cpp/test/Ice/timeout/TestI.cpp
index 01e95bea34c..e97be228af9 100644
--- a/cpp/test/Ice/timeout/TestI.cpp
+++ b/cpp/test/Ice/timeout/TestI.cpp
@@ -26,7 +26,9 @@ public:
virtual void
run()
{
+ cerr << "holdx start: " << IceUtil::Time::now().toDateTime() << endl;
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(_timeout));
+ cerr << "holdx finished: " << IceUtil::Time::now().toDateTime() << endl;
_adapter->activate();
}
@@ -52,17 +54,31 @@ TimeoutI::sleep(Ice::Int to, const Ice::Current& c)
IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(to));
}
+ControllerI::ControllerI(const Ice::ObjectAdapterPtr& adapter) : _adapter(adapter)
+{
+}
+
+void
+ControllerI::holdAdapter(Ice::Int to, const Ice::Current&)
+{
+ _adapter->hold();
+
+ if(to >= 0)
+ {
+ IceUtil::ThreadPtr thread = new ActivateAdapterThread(_adapter, to);
+ IceUtil::ThreadControl threadControl = thread->start();
+ threadControl.detach();
+ }
+}
+
void
-TimeoutI::holdAdapter(Ice::Int to, const Ice::Current& current)
+ControllerI::resumeAdapter(const Ice::Current&)
{
- current.adapter->hold();
- IceUtil::ThreadPtr thread = new ActivateAdapterThread(current.adapter, to);
- IceUtil::ThreadControl threadControl = thread->start();
- threadControl.detach();
+ _adapter->activate();
}
void
-TimeoutI::shutdown(const Ice::Current& current)
+ControllerI::shutdown(const Ice::Current&)
{
- current.adapter->getCommunicator()->shutdown();
+ _adapter->getCommunicator()->shutdown();
}
diff --git a/cpp/test/Ice/timeout/TestI.h b/cpp/test/Ice/timeout/TestI.h
index 737913beadb..8655aea585a 100644
--- a/cpp/test/Ice/timeout/TestI.h
+++ b/cpp/test/Ice/timeout/TestI.h
@@ -20,8 +20,21 @@ public:
virtual void op(const Ice::Current&);
virtual void sendData(ICE_IN(Test::ByteSeq), const Ice::Current&);
virtual void sleep(Ice::Int, const Ice::Current&);
+};
+
+class ControllerI : public virtual Test::Controller
+{
+public:
+
+ ControllerI(const Ice::ObjectAdapterPtr&);
+
virtual void holdAdapter(Ice::Int, const Ice::Current&);
+ virtual void resumeAdapter(const Ice::Current&);
virtual void shutdown(const Ice::Current&);
+
+private:
+
+ const Ice::ObjectAdapterPtr _adapter;
};
#endif