11167: Merge branch 'master' into 11167-wb-remove-arvget
[arvados.git] / services / nodemanager / arvnodeman / timedcallback.py
index 4d2a1394df2b69b3823b8120524e06af7bcb7cb5..e7e3f25fe383239c310f72e2bd234cefc46f9619 100644 (file)
@@ -19,11 +19,15 @@ class TimedCallBackActor(actor_class):
     message at a later time.  This actor runs the necessary event loop for
     delivery.
     """
-    def __init__(self, max_sleep=1):
+    def __init__(self, max_sleep=1, timefunc=None):
         super(TimedCallBackActor, self).__init__()
         self._proxy = self.actor_ref.tell_proxy()
         self.messages = []
         self.max_sleep = max_sleep
+        if timefunc is None:
+            self._timefunc = time.time
+        else:
+            self._timefunc = timefunc
 
     def schedule(self, delivery_time, receiver, *args, **kwargs):
         if not self.messages:
@@ -33,7 +37,7 @@ class TimedCallBackActor(actor_class):
     def deliver(self):
         if not self.messages:
             return
-        til_next = self.messages[0][0] - time.time()
+        til_next = self.messages[0][0] - self._timefunc()
         if til_next <= 0:
             t, receiver, args, kwargs = heapq.heappop(self.messages)
             try: