diff --git a/LCS/Messaging/python/messaging/rpc.py b/LCS/Messaging/python/messaging/rpc.py index 133fa7e579dd5b117a2d20f5fcb851785dc8a74b..b509e192f0ed8f0c4ed846d640546a9372f08f60 100644 --- a/LCS/Messaging/python/messaging/rpc.py +++ b/LCS/Messaging/python/messaging/rpc.py @@ -382,10 +382,11 @@ class RPCClient(): tmp_reply_queue.address) answer = reply_receiver.receive(wait_time) + elapsed = (datetime.utcnow() - start_time).total_seconds() - if answer is None: + if answer is None or elapsed > self._timeout: raise RPCTimeoutException("rpc call to service.method=%s via exchange=%s timed out after %.1fsec" % ( - service_method, exchange, self._timeout)) + service_method, exchange, elapsed)) if not isinstance(answer, ReplyMessage): raise ValueError("rpc call to service.method=%s via exchange=%s received an unexpected non-ReplyMessage of type %s" % ( diff --git a/LCS/Messaging/python/messaging/test/t_RPC.py b/LCS/Messaging/python/messaging/test/t_RPC.py index 43f84322db20652866f4e09bbba81c76aad6025d..f8ff66b68c489b5af9c4fee10000725309bf4bb8 100644 --- a/LCS/Messaging/python/messaging/test/t_RPC.py +++ b/LCS/Messaging/python/messaging/test/t_RPC.py @@ -110,9 +110,19 @@ class TestRPC(unittest.TestCase): self._do_call_slow_method = False # notify externals that we encountered this part of the handling code event1.set() + + # calling the my_public_slow_method will cause an RPCTimeout, + # resulting in this lofar_msg not being acked + # resulting in this lofar_msg being received again, and handled again, by else below. + logger.info("handling msg %s in the slow path... calling my_public_slow_method", lofar_msg.id) rpc_client.execute("my_public_slow_method") else: + # give the rpc some slack (sometimes needed on slow systems) + rpc_client._timeout = 10 + + logger.info("handling msg %s in the fast path... calling my_public_method1", lofar_msg.id) rpc_client.execute("my_public_method1") + logger.info("handled msg %s in the fast path. called my_public_method1", lofar_msg.id) # notify externals that we encountered this part of the handling code event2.set() @@ -139,7 +149,7 @@ class TestRPC(unittest.TestCase): event1.wait(5) self.assertTrue(event1.is_set()) - event2.wait(5) + event2.wait(15) self.assertTrue(event2.is_set()) if __name__ == '__main__':