Exemplo n.º 1
0
def mock_time(start=_orig_time()):
    """
    Create a callable that will return a float that resembals a unix timestamp.
    The timestamps returned will start at the given timestamp and subsequent
    calls to the returned callable object will increase exponentially.

    :params start: a timestamp as a float

    :returns: a callable which cause be used as a replacement for time.time()
    """
    def count(start):
        growth = 1
        while True:
            yield start
            start += growth
            growth *= 2

    # start counter
    counter = count(start)

    def mock():
        # each call yields one value off the generator
        return counter.next()

    return mock
Exemplo n.º 2
0
 def now():
     # if time.time has been patched by sts then we don't want to fall into this
     # trap ourselves
     if hasattr(time, "_orig_time"):
         now = time._orig_time()
     else:
         now = time.time()
     return SyncTime(int(now), int((now * 1000000) % 1000000))
Exemplo n.º 3
0
 def now():
     # if time.time has been patched by sts then we don't want to fall into this
     # trap ourselves
     if (hasattr(time, "_orig_time")):
         now = time._orig_time()
     else:
         now = time.time()
     return SyncTime(int(now), int((now * 1000000) % 1000000))
Exemplo n.º 4
0
  def now():
    # if time.time has been patched by sts then we don't want to fall into this
    # trap ourselves
    if(hasattr(time, "_orig_time")):
      time_float = time._orig_time()
    else:
      time_float = time.time()
    time_usec = int(time_float * MILLION)
    if time_usec <= SyncTime.last_returned_time_usec:
      time_usec = SyncTime.last_returned_time_usec + 1

    now = SyncTime( time_usec / MILLION, time_usec % MILLION)
    SyncTime.last_returned_time_usec = time_usec
    return now
Exemplo n.º 5
0
  def get_time(self):
    """ Hack alert: python logging use time.time(). That means that log statements in the determinism
        protocols are going to invoke get_time again. Solve by returning the real time if we (get_time)
        are in the stacktrace """
    if self._in_get_time:
      return time._orig_time()

    try:
      self._in_get_time = True
      time_array = self.connection.request("DeterministicValue", "gettimeofday")
      sync_time =  SyncTime(*time_array)
      return sync_time.as_float()
    finally:
      self._in_get_time = False
Exemplo n.º 6
0
    def now():
        # if time.time has been patched by sts then we don't want to fall into this
        # trap ourselves
        if hasattr(time, "_orig_time"):
            time_float = time._orig_time()
        else:
            time_float = time.time()
        time_usec = int(time_float * MILLION)
        if time_usec <= SyncTime.last_returned_time_usec:
            time_usec = SyncTime.last_returned_time_usec + 1

        now = SyncTime(time_usec / MILLION, time_usec % MILLION)
        SyncTime.last_returned_time_usec = time_usec
        return now
Exemplo n.º 7
0
    def get_time(self):
        """ Hack alert: python logging use time.time(). That means that log statements in the determinism
        protocols are going to invoke get_time again. Solve by returning the real time if we (get_time)
        are in the stacktrace """
        if self._in_get_time:
            return time._orig_time()

        try:
            self._in_get_time = True
            time_array = self.connection.request("DeterministicValue",
                                                 "gettimeofday")
            sync_time = SyncTime(*time_array)
            return sync_time.as_float()
        finally:
            self._in_get_time = False
Exemplo n.º 8
0
def mock_time(start=_orig_time()):
    """
    Create a callable that will return a float that resembals a unix timestamp.
    The timestamps returned will start at the given timestamp and subsequent
    calls to the returned callable object will increase exponentially.

    :params start: a timestamp as a float

    :returns: a callable which cause be used as a replacement for time.time()
    """
    def count(start):
        growth = 1
        while True:
            yield start
            start += growth
            growth *= 2
    # start counter
    counter = count(start)

    def mock():
        # each call yields one value off the generator
        return counter.next()
    return mock
Exemplo n.º 9
0
def unpatched_time():
  if hasattr(time, "_orig_time"):
    return time._orig_time()
  else:
    return time.time()
Exemplo n.º 10
0
Arquivo: base.py Projeto: MurphyMc/sts
def unpatched_time():
  if hasattr(time, "_orig_time"):
    return time._orig_time()
  else:
    return time.time()
Exemplo n.º 11
0
 def setUp(self):
     start = _orig_time()
     manifest.time = mock_time(start)
     self.time = mock_time(start)
Exemplo n.º 12
0
 def setUp(self):
     start = _orig_time()
     manifest.time = mock_time(start)
     self.time = mock_time(start)