Example #1
0
 def test_when_not_ready(self, retry, TaskSetResult):
     callback = Mock()
     result = Mock(attrs=dict(ready=lambda: False))
     TaskSetResult.restore = lambda setid: result
     chords._unlock_chord("setid", callback, interval=10, max_retries=30)
     self.assertFalse(callback.delay.call_count)
     # did retry
     chords._unlock_chord.retry.assert_called_with(countdown=10,
                                                  max_retries=30)
Example #2
0
 def test_unlock_ready(self, retry, TaskSetResult):
     callback = Mock()
     result = Mock(attrs=dict(ready=lambda: True,
                              join=lambda **kw: [2, 4, 8, 6]))
     TaskSetResult.restore = lambda setid: result
     subtask, chords.subtask = chords.subtask, passthru
     try:
         chords._unlock_chord("setid", callback)
     finally:
         chords.subtask = subtask
     callback.delay.assert_called_with([2, 4, 8, 6])
     result.delete.assert_called_with()
     # did not retry
     self.assertFalse(retry.call_count)
Example #3
0
    def test_unlock_ready(self, retry):
        callback.apply_async = Mock()

        pts, chords.TaskSetResult = chords.TaskSetResult, TSR
        subtask, chords.subtask = chords.subtask, passthru
        try:
            chords._unlock_chord("setid", callback.subtask(),
                    result=map(AsyncResult, [1, 2, 3]))
        finally:
            chords.subtask = subtask
            chords.TaskSetResult = pts
        callback.apply_async.assert_called_with(([2, 4, 8, 6], ), {})
        # did not retry
        self.assertFalse(retry.call_count)
Example #4
0
    def test_unlock_ready(self, retry):
        callback.apply_async = Mock()

        pts, chords.TaskSetResult = chords.TaskSetResult, TSR
        subtask, chords.subtask = chords.subtask, passthru
        try:
            chords._unlock_chord("setid",
                                 callback.subtask(),
                                 result=map(AsyncResult, [1, 2, 3]))
        finally:
            chords.subtask = subtask
            chords.TaskSetResult = pts
        callback.apply_async.assert_called_with(([2, 4, 8, 6], ), {})
        # did not retry
        self.assertFalse(retry.call_count)
Example #5
0
    def test_when_not_ready(self, retry, TaskSetResult):
        callback.apply_async = Mock()

        class NeverReady(TSR):
            is_ready = False

        pts, chords.TaskSetResult = chords.TaskSetResult, NeverReady
        try:
            chords._unlock_chord("setid", callback.subtask, interval=10,
                                max_retries=30,
                                result=map(AsyncResult, [1, 2, 3]))
            self.assertFalse(callback.apply_async.call_count)
            # did retry
            chords._unlock_chord.retry.assert_called_with(countdown=10,
                                                          max_retries=30)
        finally:
            chords.TaskSetResult = pts
Example #6
0
    def test_when_not_ready(self, retry, TaskSetResult):
        callback.apply_async = Mock()

        class NeverReady(TSR):
            is_ready = False

        pts, chords.TaskSetResult = chords.TaskSetResult, NeverReady
        try:
            chords._unlock_chord("setid",
                                 callback.subtask,
                                 interval=10,
                                 max_retries=30,
                                 result=map(AsyncResult, [1, 2, 3]))
            self.assertFalse(callback.apply_async.call_count)
            # did retry
            chords._unlock_chord.retry.assert_called_with(countdown=10,
                                                          max_retries=30)
        finally:
            chords.TaskSetResult = pts