class TestRoundTripAsynchronous(unittest.TestCase): def setUp(self): self.logger = LogManager().getLogger("test") self.mr = MyResult() # Create the IPC: tmHead = TransactionManager(HeadTransactionIdGenerator()) tmNeck = TransactionManager(NeckTransactionIdGenerator()) self.hl = My1Listener() self.nl = My1Listener() self.qTransport = QueueTransportDetails() self.ipcHead = QueueTransporter(self.qTransport, tmHead, self.hl, logger=LogManager().getLogger("Head")) self.ipcNeck = QueueTransporter(self.qTransport.invert(), tmNeck, self.nl, logger=LogManager().getLogger("Neck")) # Symmetrical api: self.apiHead = Api("test") self.apiHead.ipc = self.ipcHead self.apiNeck = Api("test", solicited=True) self.apiNeck.ipc = self.ipcNeck # Set the expected result object: self.apiNeck.parent.eResult = self.mr def tearDown(self): self.ipcHead.close(ignoreErrors=True) self.ipcNeck.close(ignoreErrors=True) try: self.apiHead.teardown() except: pass try: self.apiNeck.teardown() except: pass def test(self): self.ipcHead.connect() self.ipcNeck.connect() args = (0, 1, 2, 3) kwargs = {"four":4, "five":5} api = self.apiHead.parent.method_a(*args, **kwargs) self.mr.returnExact = True # Make the call asynchronous: api.sync = eSync.ASYNCHRONOUS asyncResult = api() assert isinstance(asyncResult, iAsyncResult) # Now wait on the asynchronous result: result = asyncResult.acquireNew() assert result == (args, kwargs) # Check that the tId is NOT purged. assert asyncResult.tId() in self.ipcHead.getTransactionManager()._items def testWithPurge(self): self.ipcHead.connect() self.ipcNeck.connect() args = (0, 1, 2, 3) kwargs = {"four":4, "five":5} api = self.apiHead.parent.method_a(*args, **kwargs) self.mr.returnExact = True # Make the call asynchronous: api.sync = eSync.ASYNCHRONOUS asyncResult = api() assert isinstance(asyncResult, iAsyncResult) # Now wait on the asynchronous result: result = asyncResult.acquireNew(purge=True) assert result == (args, kwargs) # Check that the tId IS purged. assert asyncResult.tId() not in self.ipcHead.getTransactionManager()._items def testCustomResult(self): eResult = Result() self.apiHead.parent.eResult = eResult self.ipcHead.connect() self.ipcNeck.connect() args = (0, 1, 2, 3) kwargs = {"four":4, "five":5} api = self.apiHead.parent.method_a(*args, **kwargs) # Make the call asynchronous: api.sync = eSync.ASYNCHRONOUS self.mr.returnExact = False self.mr.altResult = eResult asyncResult = api() assert isinstance(asyncResult, iAsyncResult) # Now wait on the asynchronous result: result = asyncResult.acquireNew() assert result.args == eResult.args, "Got: %(R)s" % {"R":result} def testCustomExceptionResult(self): eResult = ExceptionResult() self.apiHead.parent.eResult = eResult self.ipcHead.connect() self.ipcNeck.connect() args = (0, 1, 2, 3) kwargs = {"four":4, "five":5} api = self.apiHead.parent.method_a(*args, **kwargs) # Make the call asynchronous: api.sync = eSync.ASYNCHRONOUS self.mr.returnExact = False self.mr.altResult = eResult asyncResult = api() assert isinstance(asyncResult, iAsyncResult) try: # Now wait on the asynchronous result: asyncResult.acquireNew() except ExceptionResult, _result: assert True else: