Esempio n. 1
0
    def test_last_poll_time_updates_when_wait_completes(self):
        self.mock_clock.now.return_value = datetime.datetime(2017,
                                                             4,
                                                             9,
                                                             11,
                                                             43,
                                                             29,
                                                             tzinfo=pytz.utc)
        scheduler = poller.Scheduler(
            self.mock_clock, poll_interval=datetime.timedelta(minutes=5))

        # If a poll completes, last_poll_time should update to the last poll
        # time.
        self.assertTrue(scheduler.wait_until_poll_time(timeout=120))
        self.assertEqual(
            datetime.datetime(2017, 4, 9, 11, 45, 0, tzinfo=pytz.utc),
            scheduler.last_poll_time())

        self.mock_clock.now.return_value = datetime.datetime(2017,
                                                             4,
                                                             9,
                                                             11,
                                                             49,
                                                             29,
                                                             tzinfo=pytz.utc)
        self.assertTrue(scheduler.wait_until_poll_time(timeout=120))
        self.assertEqual(
            datetime.datetime(2017, 4, 9, 11, 50, 0, tzinfo=pytz.utc),
            scheduler.last_poll_time())
Esempio n. 2
0
 def test_last_poll_time_is_None_before_wait_called(self):
     self.mock_clock.now.return_value = datetime.datetime(2017,
                                                          4,
                                                          9,
                                                          11,
                                                          43,
                                                          29,
                                                          tzinfo=pytz.utc)
     scheduler = poller.Scheduler(
         self.mock_clock, poll_interval=datetime.timedelta(minutes=5))
     # If no poll has happened, last_poll_time should be None.
     self.assertIsNone(scheduler.last_poll_time())
Esempio n. 3
0
 def test_no_wait_if_first_call_is_on_interval_boundary(self):
     self.mock_clock.now.return_value = datetime.datetime(2017,
                                                          4,
                                                          9,
                                                          11,
                                                          45,
                                                          0,
                                                          tzinfo=pytz.utc)
     scheduler = poller.Scheduler(
         self.mock_clock, poll_interval=datetime.timedelta(minutes=5))
     self.assertTrue(scheduler.wait_until_poll_time(timeout=(10 * 60)))
     # 11:45:00 falls on the interval boundary of 5m, so should be no wait.
     self.mock_clock.wait.assert_not_called()
Esempio n. 4
0
 def test_wait_equal_to_timeout_returns_True(self):
     self.mock_clock.now.return_value = datetime.datetime(2017,
                                                          4,
                                                          9,
                                                          11,
                                                          43,
                                                          29,
                                                          tzinfo=pytz.utc)
     scheduler = poller.Scheduler(
         self.mock_clock, poll_interval=datetime.timedelta(minutes=5))
     # If it's 11:43:29, at 5m polling intervals, next poll is at 11:45:00,
     # 91 seconds later, so timeout is equal to wait time.
     self.assertTrue(scheduler.wait_until_poll_time(timeout=91))
     self.mock_clock.wait.assert_called_with(91)
Esempio n. 5
0
 def test_wait_more_than_timeout_returns_False(self):
     self.mock_clock.now.return_value = datetime.datetime(2017,
                                                          4,
                                                          9,
                                                          11,
                                                          43,
                                                          29,
                                                          tzinfo=pytz.utc)
     scheduler = poller.Scheduler(
         self.mock_clock, poll_interval=datetime.timedelta(minutes=5))
     # If it's 11:43:29, at 5m polling intervals, next poll is at 11:45:00,
     # 91 seconds later, so we should only wait the length of the timeout.
     self.assertFalse(scheduler.wait_until_poll_time(timeout=90))
     self.mock_clock.wait.assert_called_with(90)
Esempio n. 6
0
    def test_last_poll_time_is_None_before_poll_wait_completes(self):
        self.mock_clock.now.return_value = datetime.datetime(2017,
                                                             4,
                                                             9,
                                                             11,
                                                             43,
                                                             29,
                                                             tzinfo=pytz.utc)
        scheduler = poller.Scheduler(
            self.mock_clock, poll_interval=datetime.timedelta(minutes=5))

        # If we wait for poll, but timeout is not long enough for a poll to
        # happen, last_poll_time should not change.
        self.assertFalse(scheduler.wait_until_poll_time(timeout=30))
        self.assertIsNone(scheduler.last_poll_time())
Esempio n. 7
0
 def test_increments_wait_if_consecutive_calls_on_same_poll_boundary(self):
     self.mock_clock.now.return_value = datetime.datetime(2017,
                                                          4,
                                                          9,
                                                          11,
                                                          45,
                                                          0,
                                                          tzinfo=pytz.utc)
     scheduler = poller.Scheduler(
         self.mock_clock, poll_interval=datetime.timedelta(minutes=5))
     self.assertTrue(scheduler.wait_until_poll_time(timeout=(10 * 60)))
     # First call should have no wait because it's on a poll interval
     # boundary.
     self.mock_clock.wait.assert_not_called()
     # On next call, we should wait until the *next* poll interval boundary.
     self.assertTrue(scheduler.wait_until_poll_time(timeout=(10 * 60)))
     self.mock_clock.wait.assert_called_with(5 * 60)