diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-09-15 12:18:41 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-09-15 12:18:41 +0200 |
commit | a4fb9c391caabef6de9cfbd126f4fe10755ece49 (patch) | |
tree | 36dfe5b0a110dddd09f49882649d8c2de825f4b4 /python | |
parent | Removed Eclipse .launch files (diff) | |
download | ice-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 'python')
-rw-r--r-- | python/test/Ice/timeout/AllTests.py | 69 | ||||
-rwxr-xr-x | python/test/Ice/timeout/Client.py | 4 | ||||
-rwxr-xr-x | python/test/Ice/timeout/Server.py | 23 | ||||
-rw-r--r-- | python/test/Ice/timeout/Test.ice | 5 |
4 files changed, 68 insertions, 33 deletions
diff --git a/python/test/Ice/timeout/AllTests.py b/python/test/Ice/timeout/AllTests.py index d65742cb335..3023398b75a 100644 --- a/python/test/Ice/timeout/AllTests.py +++ b/python/test/Ice/timeout/AllTests.py @@ -68,24 +68,29 @@ def allTests(communicator): timeout = Test.TimeoutPrx.checkedCast(obj) test(timeout != None) + controller = Test.ControllerPrx.checkedCast(communicator.stringToProxy("controller:default -p 12011")) + test(controller != None) + sys.stdout.write("testing connect timeout... ") sys.stdout.flush() # # Expect ConnectTimeoutException. # to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(100)) - timeout.holdAdapter(500) + controller.holdAdapter(-1) try: to.op() test(False) except Ice.ConnectTimeoutException: pass # Expected. + controller.resumeAdapter() + timeout.op() # Ensure adapter is active. + # # Expect success. # - timeout.op() # Ensure adapter is active. to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(1000)) - timeout.holdAdapter(500) + controller.holdAdapter(200) try: to.op() except Ice.ConnectTimeoutException: @@ -106,18 +111,19 @@ def allTests(communicator): seq = bytes([0 for x in range(0, 10000000)]) to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(250)) connect(to) - timeout.holdAdapter(750) + controller.holdAdapter(-1) try: to.sendData(seq) test(False) except Ice.TimeoutException: pass # Expected. + controller.resumeAdapter() + timeout.op() # Ensure adapter is active. # # Expect success. # - timeout.op() # Ensure adapter is active. to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(1000)) - timeout.holdAdapter(500) + controller.holdAdapter(200) try: if sys.version_info[0] == 2: seq2 = [] @@ -137,7 +143,7 @@ def allTests(communicator): to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(100)) test(connection == to.ice_getConnection()) try: - to.sleep(750) + to.sleep(500) test(False) except Ice.InvocationTimeoutException: pass @@ -155,7 +161,7 @@ def allTests(communicator): # # # to = Test.TimeoutPrx.uncheckedCast(obj.ice_invocationTimeout(250)) # 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() # # @@ -171,19 +177,21 @@ def allTests(communicator): sys.stdout.flush() to = Test.TimeoutPrx.uncheckedCast(obj.ice_timeout(250)) connection = connect(to) - timeout.holdAdapter(600) + controller.holdAdapter(-1) connection.close(Ice.ConnectionClose.GracefullyWithWait) try: connection.getInfo(); # getInfo() doesn't throw in the closing state. except Ice.LocalException: test(False) - time.sleep(0.65) - try: - connection.getInfo() - test(False) - except Ice.ConnectionManuallyClosedException as ex: - # Expected. - test(ex.graceful) + while True: + try: + connection.getInfo() + time.sleep(0.001) + except Ice.ConnectionManuallyClosedException as ex: + # Expected. + test(ex.graceful) + break + controller.resumeAdapter() timeout.op() # Ensure adapter is active. print("ok") @@ -201,24 +209,28 @@ def allTests(communicator): comm = Ice.initialize(initData) to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(sref)) connect(to) - timeout.holdAdapter(500) + controller.holdAdapter(-1) try: to.sendData(seq) test(False) except Ice.TimeoutException: pass # Expected. + controller.resumeAdapter() + timeout.op() # Ensure adapter is active. + # # Calling ice_timeout() should have no effect. # - timeout.op() # Ensure adapter is active. to = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(1000)) connect(to) - timeout.holdAdapter(500) + controller.holdAdapter(-1) try: to.sendData(seq) test(False) except Ice.TimeoutException: pass # Expected. + controller.resumeAdapter() + timeout.op() # Ensure adapter is active. comm.destroy() # # Test Ice.Override.ConnectTimeout. @@ -227,36 +239,40 @@ def allTests(communicator): initData.properties = communicator.getProperties().clone() initData.properties.setProperty("Ice.Override.ConnectTimeout", "250") comm = Ice.initialize(initData) - timeout.holdAdapter(750) + controller.holdAdapter(-1) to = Test.TimeoutPrx.uncheckedCast(comm.stringToProxy(sref)) try: to.op() test(False) except Ice.ConnectTimeoutException: pass # 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 = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(1000)) try: to.op() test(False) except Ice.ConnectTimeoutException: pass # 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 = Test.TimeoutPrx.uncheckedCast(to.ice_timeout(250)) connect(to) - timeout.holdAdapter(750) + controller.holdAdapter(-1) try: to.sendData(seq) test(False) except Ice.TimeoutException: pass # Expected. + controller.resumeAdapter() + timeout.op() # Ensure adapter is active. comm.destroy() # @@ -267,11 +283,12 @@ def allTests(communicator): initData.properties.setProperty("Ice.Override.CloseTimeout", "100") comm = Ice.initialize(initData) connection = comm.stringToProxy(sref).ice_getConnection() - timeout.holdAdapter(800) + controller.holdAdapter(-1) now = time.clock() comm.destroy() test((time.clock() - now) < 0.7) + controller.resumeAdapter() print("ok") - return timeout + controller.shutdown() diff --git a/python/test/Ice/timeout/Client.py b/python/test/Ice/timeout/Client.py index 9d6bd83e625..31ecdc34d09 100755 --- a/python/test/Ice/timeout/Client.py +++ b/python/test/Ice/timeout/Client.py @@ -23,9 +23,7 @@ def test(b): raise RuntimeError('test assertion failed') def run(args, communicator): - timeout = AllTests.allTests(communicator) - timeout.shutdown() - + AllTests.allTests(communicator) return True try: diff --git a/python/test/Ice/timeout/Server.py b/python/test/Ice/timeout/Server.py index 917f8e90017..33bc4e780ac 100755 --- a/python/test/Ice/timeout/Server.py +++ b/python/test/Ice/timeout/Server.py @@ -40,19 +40,36 @@ class TimeoutI(Test.Timeout): if timeout != 0: time.sleep(timeout / 1000.0) +class ControllerI(Test.Controller): + + def __init__(self, adapter): + self.adapter = adapter + def holdAdapter(self, to, current=None): - current.adapter.hold() - t = ActivateAdapterThread(current.adapter, to) - t.start() + self.adapter.hold() + if to >= 0: + t = ActivateAdapterThread(self.adapter, to) + t.start() + + def resumeAdapter(self, current=None): + self.adapter.activate() def shutdown(self, current=None): current.adapter.getCommunicator().shutdown() def run(args, communicator): communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010") + communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "default -p 12011"); + communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1"); + adapter = communicator.createObjectAdapter("TestAdapter") adapter.add(TimeoutI(), Ice.stringToIdentity("timeout")) adapter.activate() + + controllerAdapter = communicator.createObjectAdapter("ControllerAdapter") + controllerAdapter.add(ControllerI(adapter), Ice.stringToIdentity("controller")) + controllerAdapter.activate() + communicator.waitForShutdown() return True diff --git a/python/test/Ice/timeout/Test.ice b/python/test/Ice/timeout/Test.ice index aad831a9993..d611817c1ac 100644 --- a/python/test/Ice/timeout/Test.ice +++ b/python/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(); } |