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()
Пример #2
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()
Пример #3
0
    def test_utcnow(self):
        timeutils.set_time_override(mock.sentinel.utcnow)
        self.assertEqual(timeutils.utcnow(), mock.sentinel.utcnow)

        timeutils.clear_time_override()
        self.assertFalse(timeutils.utcnow() == mock.sentinel.utcnow)

        self.assertTrue(timeutils.utcnow())
Пример #4
0
    def test_utcnow(self):
        timeutils.set_time_override(mock.sentinel.utcnow)
        self.assertEqual(timeutils.utcnow(), mock.sentinel.utcnow)

        timeutils.clear_time_override()
        self.assertFalse(timeutils.utcnow() == mock.sentinel.utcnow)

        self.assertTrue(timeutils.utcnow())
Пример #5
0
 def test_timeout(self):
     try:
         now = datetime.datetime.utcnow()
         timeutils.set_time_override(now)
         self.client.set('foo', 'bar', time=3)
         timeutils.set_time_override(now + datetime.timedelta(seconds=1))
         self.assertEqual(self.client.get('foo'), 'bar')
         timeutils.set_time_override(now + datetime.timedelta(seconds=3))
         self.assertEqual(self.client.get('foo'), None)
     finally:
         timeutils.clear_time_override()
Пример #6
0
 def tearDown(self):
     timeutils.clear_time_override()
Пример #7
0
 def tearDown(self):
     timeutils.clear_time_override()