Ejemplo n.º 1
0
    def test_interval_adjustment(self):
        """Ensure the interval is adjusted to account for task duration"""
        self.num_runs = 3

        now = datetime.datetime.utcnow()
        second = datetime.timedelta(seconds=1)
        smidgen = datetime.timedelta(microseconds=10000)
        timeoverrides = [
            now, now + second - smidgen, now, now + second + second, now,
            now + second + smidgen
        ]

        m = mox.Mox()
        m.StubOutWithMock(greenthread, 'sleep')
        greenthread.sleep(mox.IsAlmost(0.02))
        greenthread.sleep(mox.IsAlmost(0.0))
        greenthread.sleep(mox.IsAlmost(0.0))
        m.ReplayAll()

        try:
            timeutils.set_time_override(timeoverrides)
            timer = loopingcall.LoopingCall(self._wait_for_zero)
            timer.start(interval=1.01).wait()
        finally:
            timeutils.clear_time_override()
            m.UnsetStubs()
            m.VerifyAll()
Ejemplo n.º 2
0
 def add_timer(self,
               interval,
               callback,
               initial_delay=None,
               *args,
               **kwargs):
     pulse = loopingcall.LoopingCall(callback, *args, **kwargs)
     pulse.start(interval=interval, initial_delay=initial_delay)
     self.timers.append(pulse)
Ejemplo n.º 3
0
    def test_repeat(self):
        self.num_runs = 2

        def _wait_for_zero():
            """Called at an interval until num_runs == 0."""
            if self.num_runs == 0:
                raise loopingcall.LoopingCallDone(False)
            else:
                self.num_runs = self.num_runs - 1

        timer = loopingcall.LoopingCall(_wait_for_zero)
        self.assertFalse(timer.start(interval=0.5).wait())
Ejemplo n.º 4
0
    def test_repeat(self):
        self.num_runs = 2

        timer = loopingcall.LoopingCall(self._wait_for_zero)
        self.assertFalse(timer.start(interval=0.5).wait())
Ejemplo n.º 5
0
    def test_return_false(self):
        def _raise_it():
            raise loopingcall.LoopingCallDone(False)

        timer = loopingcall.LoopingCall(_raise_it)
        self.assertFalse(timer.start(interval=0.5).wait())