def test_markers_and_context_complete(self, mark, context_from_id, check_markers): """Ensure if all markers are complete that True is returned and nothing else is done. """ async = Async('foo') async.update_options(context_id='contextid') complete_event = Mock() context = Context(id="contextid", callbacks={'complete': complete_event}) context_from_id.return_value = context marker = FuriousCompletionMarker(id="contextid", complete=True) marker.put() check_markers.return_value = True, False mark.return_value = True result = _completion_checker(async.id, async.context_id) self.assertTrue(result) self.assertFalse(complete_event.start.called) marker.key.delete()
def test_markers_and_context_complete(self, mark, context_from_id, check_markers): """Ensure if all markers are complete that True is returned and nothing else is done. """ async = Async('foo') async .update_options(context_id='contextid') complete_event = Mock() context = Context(id="contextid", callbacks={'complete': complete_event}) context_from_id.return_value = context marker = FuriousCompletionMarker(id="contextid", complete=True) marker.put() check_markers.return_value = True, False mark.return_value = True result = _completion_checker(async .id, async .context_id) self.assertTrue(result) self.assertFalse(complete_event.start.called) marker.key.delete()
def test_has_errors_with_marker_cached(self): """Ensure returns the value from the marker when cached.""" context_id = 1 marker = FuriousCompletionMarker(id=context_id, has_errors=True) marker.put() context = Context(id=context_id) context._marker = marker context_result = ContextResult(context) self.assertIsNone(context_result._marker) self.assertTrue(context_result.has_errors()) marker.key.delete()
def test_marker_not_complete_when_start_fails(self, mock_insert, context_from_id, check_markers): """Ensure if the completion handler fails to start, that the marker does not get marked as complete. """ complete_event = Mock() context = Context(id="contextid", callbacks={'complete': complete_event}) context_from_id.return_value = context check_markers.return_value = True, False async = Async('foo') async.update_options(context_id='contextid') FuriousCompletionMarker(id=async.context_id, complete=False).put() # Simulate the task failing to start mock_insert.side_effect = DeadlineExceededError() self.assertRaises(DeadlineExceededError, _completion_checker, async.id, async.context_id) # Marker should not have been marked complete. current_marker = FuriousCompletionMarker.get_by_id(async.context_id) self.assertFalse(current_marker.complete)
def test_marker_not_complete_when_start_fails(self, mock_insert, context_from_id, check_markers): """Ensure if the completion handler fails to start, that the marker does not get marked as complete. """ complete_event = Mock() context = Context(id="contextid", callbacks={'complete': complete_event}) context_from_id.return_value = context check_markers.return_value = True, False async = Async('foo') async .update_options(context_id='contextid') FuriousCompletionMarker(id=async .context_id, complete=False).put() # Simulate the task failing to start mock_insert.side_effect = DeadlineExceededError() self.assertRaises(DeadlineExceededError, _completion_checker, async .id, async .context_id) # Marker should not have been marked complete. current_marker = FuriousCompletionMarker.get_by_id(async .context_id) self.assertFalse(current_marker.complete)
def test_markers_complete(self, context_from_id, check_markers): """Ensure if all markers are complete that True is returned and the completion handler and cleanup tasks are triggered. """ complete_event = Mock() context = Context(id="contextid", callbacks={'complete': complete_event}) context_from_id.return_value = context check_markers.return_value = True, False async = Async('foo') async .update_options(context_id='contextid') FuriousCompletionMarker(id=async .context_id, complete=False).put() result = _completion_checker(async .id, async .context_id) self.assertTrue(result) complete_event.start.assert_called_once_with(transactional=True)