def simulated_time_advance(self, secs): while (secs > 0): print "T=%s: Want to advance by %s" % (self.current_time, secs) # Determine the time to advance to in this iteration: either the # full time that we've been asked for, or the time at which the # next sleeper should wake up, whichever of those is earlier. wake_up_time = self.current_time + secs for queue in self.sleepers.keys(): if self.sleepers[queue] < wake_up_time: # This sleeper will wake up before the time that we've been # asked to advance to. wake_up_time = self.sleepers[queue] # Advance to the determined time. secs -= (wake_up_time - self.current_time) self.current_time = wake_up_time print "T=%s" % self.current_time # Wake up all sleepers that should now wake up. for queue in self.sleepers.keys(): if self.sleepers[queue] <= self.current_time: print "T=%s >= %s: %s: Wake up!" % (self.current_time, self.sleepers[queue], queue.stack) del self.sleepers[queue] queue.put_nowait(TIMEOUT_VALUE) # Allow woken (and possibly other) threads to run. self.real_eventlet_sleep(REAL_EVENTLET_SLEEP_TIME)
def simulated_time_advance(self, secs): while (secs > 0): _log.info("T=%s: Want to advance by %s", self.current_time, secs) # Determine the time to advance to in this iteration: either the # full time that we've been asked for, or the time at which the # next sleeper should wake up, whichever of those is earlier. wake_up_time = self.current_time + secs for queue in self.sleepers.keys(): if self.sleepers[queue] < wake_up_time: # This sleeper will wake up before the time that we've been # asked to advance to. wake_up_time = self.sleepers[queue] # Advance to the determined time. secs -= (wake_up_time - self.current_time) self.current_time = wake_up_time _log.info("T=%s", self.current_time) # Wake up all sleepers that should now wake up. for queue in self.sleepers.keys(): if self.sleepers[queue] <= self.current_time: _log.info("T=%s >= %s: %s: Wake up!", self.current_time, self.sleepers[queue], queue.stack) del self.sleepers[queue] queue.put_nowait(TIMEOUT_VALUE) # Allow woken (and possibly other) threads to run. self.real_eventlet_sleep(REAL_EVENTLET_SLEEP_TIME)
def simulated_time_advance(self, secs): global current_time while (secs > 0): print "T=%s: Want to advance by %s" % (current_time, secs) # Determine the time to advance to in this iteration: either the # full time that we've been asked for, or the time at which the # next sleeper should wake up, whichever of those is earlier. wake_up_time = current_time + secs for queue in sleepers.keys(): if sleepers[queue] < wake_up_time: # This sleeper will wake up before the time that we've been # asked to advance to. wake_up_time = sleepers[queue] # Check if we're about to advance past any exact multiples of # HEARTBEAT_SEND_INTERVAL_SECS. num_acl_pub_heartbeats = ( int(wake_up_time / mech_calico.HEARTBEAT_SEND_INTERVAL_SECS) - int(current_time / mech_calico.HEARTBEAT_SEND_INTERVAL_SECS) ) # Advance to the determined time. secs -= (wake_up_time - current_time) current_time = wake_up_time print "T=%s" % current_time # Wake up all sleepers that should now wake up. for queue in sleepers.keys(): if sleepers[queue] <= current_time: print "T=%s >= %s: %s: Wake up!" % (current_time, sleepers[queue], queue.stack) del sleepers[queue] queue.put_nowait(TIMEOUT_VALUE) # Allow woken (and possibly other) threads to run. real_eventlet_sleep(REAL_EVENTLET_SLEEP_TIME) # Handle any ACL HEARTBEAT publications. for i in range(num_acl_pub_heartbeats): print "Handle ACL HEARTBEAT publication" pub = {'type': 'HEARTBEAT', 'issued': current_time * 1000} self.acl_pub_socket.send_multipart.assert_called_once_with( ['networkheartbeat'.encode('utf-8'), json.dumps(pub).encode('utf-8')]) self.acl_pub_socket.send_multipart.reset_mock()