예제 #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)

        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.StubOutWithMock(timeutils, 'utcnow')
        timeutils.utcnow().AndReturn(now)
        timeutils.utcnow().AndReturn(now + second - smidgen)
        timeutils.utcnow().AndReturn(now)
        timeutils.utcnow().AndReturn(now + second + second)
        timeutils.utcnow().AndReturn(now)
        timeutils.utcnow().AndReturn(now + second + smidgen)
        timeutils.utcnow().AndReturn(now)
        m.ReplayAll()

        timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_zero)
        timer.start(interval=1.01).wait()
        m.UnsetStubs()
        m.VerifyAll()
예제 #2
0
 def setUp(self):
     super(MoxStubout, self).setUp()
     # emulate some of the mox stuff, we can't use the metaclass
     # because it screws with our generators
     self.mox = mox.Mox()
     self.stubs = self.mox.stubs
     self.addCleanup(self.mox.UnsetStubs)
     self.addCleanup(self.mox.VerifyAll)
예제 #3
0
 def setUp(self):
     super(TestCachedFile, self).setUp()
     self.mox = mox.Mox()
     self.addCleanup(self.mox.UnsetStubs)