diff options
Diffstat (limited to 'python/test/Ice/acm/AllTests.py')
-rw-r--r-- | python/test/Ice/acm/AllTests.py | 119 |
1 files changed, 44 insertions, 75 deletions
diff --git a/python/test/Ice/acm/AllTests.py b/python/test/Ice/acm/AllTests.py index 5dcb67f9c32..365a0daa26f 100644 --- a/python/test/Ice/acm/AllTests.py +++ b/python/test/Ice/acm/AllTests.py @@ -20,48 +20,33 @@ class LoggerI(Ice.Logger): self.m = threading.Lock() def start(self): - self.m.acquire() - try: + with self.m: self._started = True self.dump() - finally: - self.m.release() def _print(self, msg): - self.m.acquire() - try: + with self.m: self._messages.append(msg) if self._started: self.dump() - finally: - self.m.release() def trace(self, category, msg): - self.m.acquire() - try: + with self.m: self._messages.append("[" + category + "] " + msg) if self._started: self.dump() - finally: - self.m.release() def warning(self, msg): - self.m.acquire() - try: + with self.m: self._messages.append("warning: " + msg) if self._started: self.dump() - finally: - self.m.release() def error(self, msg): - self.m.acquire() - try: + with self.m: self._messages.append("error: " + msg) if self._started: self.dump() - finally: - self.m.release() def getPrefix(self): return "" @@ -74,7 +59,7 @@ class LoggerI(Ice.Logger): print(p) self._messages = [] -class TestCase(threading.Thread, Ice.ConnectionCallback): +class TestCase(threading.Thread): def __init__(self, name, com): threading.Thread.__init__(self) self._name = name @@ -128,24 +113,20 @@ class TestCase(threading.Thread, Ice.ConnectionCallback): proxy = Test.TestIntfPrx.uncheckedCast(self._communicator.stringToProxy( self._adapter.getTestIntf().ice_toString())) try: - proxy.ice_getConnection().setCallback(self) + proxy.ice_getConnection().setCloseCallback(lambda conn: self.closed(conn)) + proxy.ice_getConnection().setHeartbeatCallback(lambda conn: self.heartbeat(conn)) + self.runTestCase(self._adapter, proxy) except Exception as ex: self._msg = "unexpected exception:\n" + traceback.format_exc() def heartbeat(self, con): - self.m.acquire() - try: + with self.m: self._heartbeat = self._heartbeat + 1 - finally: - self.m.release() def closed(self, con): - self.m.acquire() - try: + with self.m: self._closed = True - finally: - self.m.release() def runTestCase(self, adapter, proxy): test(False) @@ -173,11 +154,8 @@ def allTests(communicator): def runTestCase(self, adapter, proxy): proxy.sleep(2) - self.m.acquire() - try: + with self.m: test(self._heartbeat >= 2) - finally: - self.m.release() class InvocationHeartbeatOnHoldTest(TestCase): def __init__(self, com): @@ -195,11 +173,8 @@ def allTests(communicator): adapter.activate() proxy.interruptSleep() - self.m.acquire() - try: + with self.m: test(self._closed) - finally: - self.m.release() class InvocationNoHeartbeatTest(TestCase): def __init__(self, com): @@ -216,12 +191,9 @@ def allTests(communicator): except Ice.ConnectionTimeoutException: proxy.interruptSleep() - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(self._closed) - finally: - self.m.release() class InvocationHeartbeatCloseOnIdleTest(TestCase): def __init__(self, com): @@ -233,12 +205,9 @@ def allTests(communicator): # No close on invocation, the call should succeed this time. proxy.sleep(2) - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(not self._closed) - finally: - self.m.release() class CloseOnIdleTest(TestCase): def __init__(self, com): @@ -248,12 +217,9 @@ def allTests(communicator): def runTestCase(self, adapter, proxy): time.sleep(1.6) # Idle for 1.6 seconds - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(self._closed) - finally: - self.m.release() class CloseOnInvocationTest(TestCase): def __init__(self, com): @@ -263,12 +229,9 @@ def allTests(communicator): def runTestCase(self, adapter, proxy): time.sleep(1.5) # Idle for 1.5 seconds - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(not self._closed) - finally: - self.m.release() class CloseOnIdleAndInvocationTest(TestCase): def __init__(self, com): @@ -284,21 +247,15 @@ def allTests(communicator): adapter.hold() time.sleep(1.6) # Idle for 1.6 seconds - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(not self._closed) # Not closed yet because of graceful close. - finally: - self.m.release() adapter.activate() time.sleep(0.5) - self.m.acquire() - try: + with self.m: test(self._closed) # Connection should be closed this time. - finally: - self.m.release() class ForcefulCloseOnIdleAndInvocationTest(TestCase): def __init__(self, com): @@ -309,12 +266,9 @@ def allTests(communicator): adapter.hold() time.sleep(1.6) # Idle for 1.6 seconds - self.m.acquire() - try: + with self.m: test(self._heartbeat == 0) test(self._closed) # Connection closed forcefully by ACM. - finally: - self.m.release() class HeartbeatOnIdleTest(TestCase): def __init__(self, com): @@ -324,11 +278,8 @@ def allTests(communicator): def runTestCase(self, adapter, proxy): time.sleep(2) - self.m.acquire() - try: + with self.m: test(self._heartbeat >= 3) - finally: - self.m.release() class HeartbeatAlwaysTest(TestCase): def __init__(self, com): @@ -340,11 +291,27 @@ def allTests(communicator): proxy.ice_ping() time.sleep(0.1) - self.m.acquire() - try: + with self.m: test(self._heartbeat >= 3) - finally: - self.m.release() + + class HeartbeatManualTest(TestCase): + def __init__(self, com): + TestCase.__init__(self, "manual heartbeats", com) + # + # Disable heartbeats. + # + self.setClientACM(10, -1, 0) + self.setServerACM(10, -1, 0) + + def runTestCase(self, adapter, proxy): + proxy.startHeartbeatCount() + con = proxy.ice_getConnection() + con.heartbeat() + con.heartbeat() + con.heartbeat() + con.heartbeat() + con.heartbeat() + proxy.waitForHeartbeatCount(5) class SetACMTest(TestCase): def __init__(self, com): @@ -370,7 +337,8 @@ def allTests(communicator): test(acm.close == Ice.ACMClose.CloseOnInvocationAndIdle) test(acm.heartbeat == Ice.ACMHeartbeat.HeartbeatAlways) - proxy.waitForHeartbeat(2) + proxy.startHeartbeatCount() + proxy.waitForHeartbeatCount(2) tests.append(InvocationHeartbeatTest(com)) tests.append(InvocationHeartbeatOnHoldTest(com)) @@ -384,6 +352,7 @@ def allTests(communicator): tests.append(HeartbeatOnIdleTest(com)) tests.append(HeartbeatAlwaysTest(com)) + tests.append(HeartbeatManualTest(com)) tests.append(SetACMTest(com)) for p in tests: |