def test_iterate_respects_subpolling_interval(self):
    r1 = self.app.AsyncResult(uuid())
    r2 = self.app.AsyncResult(uuid())
    backend = r1.backend = r2.backend = Mock()
    backend.subpolling_interval = 10
    ready = r1.ready = r2.ready = Mock()

    def se(*args, **kwargs):
        ready.side_effect = KeyError()
        return False
    ready.return_value = False
    ready.side_effect = se
    x = self.app.ResultSet([r1, r2])
    with self.dummy_copy():
        with patch('celery.result.time') as _time:
            with self.assertRaises(KeyError):
                list(x.iterate())
            _time.sleep.assert_called_with(10)
        backend.subpolling_interval = 0
        with patch('celery.result.time') as _time:
            with self.assertRaises(KeyError):
                ready.return_value = False
                ready.side_effect = se
                list(x.iterate())
            self.assertFalse(_time.sleep.called)
def test_iterate_respects_subpolling_interval(self):
    r1 = self.app.AsyncResult(uuid())
    r2 = self.app.AsyncResult(uuid())
    backend = r1.backend = r2.backend = Mock()
    backend.subpolling_interval = 10
    ready = r1.ready = r2.ready = Mock()

    def se(*args, **kwargs):
        ready.side_effect = KeyError()
        return False
    ready.return_value = False
    ready.side_effect = se
    x = self.app.ResultSet([r1, r2])
    with self.dummy_copy():
        with patch('celery.result.time') as _time:
            with self.assertRaises(KeyError):
                list(x.iterate())
            _time.sleep.assert_called_with(10)
        backend.subpolling_interval = 0
        with patch('celery.result.time') as _time:
            with self.assertRaises(KeyError):
                ready.return_value = False
                ready.side_effect = se
                list(x.iterate())
            self.assertFalse(_time.sleep.called)