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()
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)
def setUp(self): super(TestCachedFile, self).setUp() self.mox = mox.Mox() self.addCleanup(self.mox.UnsetStubs)