def test_fire_timers_raises(self): hub = Hub() eback = Mock() eback.side_effect = KeyError("foo") hub.timer = Mock() hub.scheduler = iter([(0, eback)]) with self.assertRaises(KeyError): hub.fire_timers(propagate=(KeyError,)) eback.side_effect = ValueError("foo") hub.scheduler = iter([(0, eback)]) with patch("kombu.async.hub.logger") as logger: with self.assertRaises(StopIteration): hub.fire_timers() self.assertTrue(logger.error.called)
def test_fire_timers_raises(self): hub = Hub() eback = Mock() eback.side_effect = KeyError('foo') hub.timer = Mock() hub.scheduler = iter([(0, eback)]) with self.assertRaises(KeyError): hub.fire_timers(propagate=(KeyError, )) eback.side_effect = ValueError('foo') hub.scheduler = iter([(0, eback)]) with patch('kombu.async.hub.logger') as logger: with self.assertRaises(StopIteration): hub.fire_timers() self.assertTrue(logger.error.called)
def test_fire_timers(self): hub = Hub() hub.timer = Mock() hub.timer._queue = [] self.assertEqual(hub.fire_timers(min_delay=42.324, max_delay=32.321), 32.321) hub.timer._queue = [1] hub.scheduler = iter([(3.743, None)]) self.assertEqual(hub.fire_timers(), 3.743) e1, e2, e3 = Mock(), Mock(), Mock() entries = [e1, e2, e3] def reset(): return [m.reset() for m in [e1, e2, e3]] def se(): while 1: while entries: yield None, entries.pop() yield 3.982, None hub.scheduler = se() self.assertEqual(hub.fire_timers(max_timers=10), 3.982) for E in [e3, e2, e1]: E.assert_called_with() reset() entries[:] = [Mock() for _ in range(11)] keep = list(entries) self.assertEqual(hub.fire_timers(max_timers=10, min_delay=1.13), 1.13) for E in reversed(keep[1:]): E.assert_called_with() reset() self.assertEqual(hub.fire_timers(max_timers=10), 3.982) keep[0].assert_called_with()