Skip to content
Snippets Groups Projects
Commit 386ef74e authored by Geoffrey Mo's avatar Geoffrey Mo
Browse files

Add unit test for check_vector retry

parent 00e0c6d0
No related branches found
No related tags found
No related merge requests found
......@@ -459,7 +459,7 @@ def check_vectors(self, event, graceid, start, end):
except ValueError as exc:
# check_vector likely failed to find the requested data
# in the cache because it has yet to arrive
raise self.retry(exc=exc, max_retries=3)
raise self.retry(exc=exc, max_retries=4)
# Pick out DQ and injection states, then filter for active detectors
dq_states = {key: value for key, value in states.items()
if key.split('_')[-1] != 'INJ'}
......
......@@ -4,6 +4,7 @@ from pathlib import Path
from unittest.mock import call, patch
from astropy.time import Time
import celery
from gwpy.timeseries import Bits
import matplotlib.pyplot as plt
import numpy as np
......@@ -324,6 +325,24 @@ def test_check_vectors_fails(
mock_remove_label.assert_called_with('DQOK', 'S12345a')
@patch('gwcelery.tasks.gracedb.upload.run')
@patch('celery.app.task.Task.request')
@patch('gwcelery.tasks.detchar.check_vector', side_effect=ValueError)
def test_check_vectors_retries_on_valueerror(
mock_check_vector, mock_request,
mock_upload, llhoft_glob_pass, ifo_h1, ifo_h1_idq):
# Mocking this retry https://docs.celeryq.dev/en/stable/_modules/celery/app/task.html#Task.retry # noqa E501
event = {'search': 'AllSky', 'instruments': 'L1', 'pipeline': 'oLIB'}
superevent_id = 'S12345a'
start, end = 1216577978, 1216577978.1
mock_request.called_directly = False
mock_request.retries = 3
with pytest.raises(celery.exceptions.Retry) as retry_exc:
detchar.check_vectors.delay(event, superevent_id, start, end)
# after three retries, should still retry once in 5 seconds
assert retry_exc.value.when == 5
@patch('gwcelery.tasks.detchar.dqr_json', return_value='dqrjson')
@patch('gwcelery.tasks.gracedb.upload.run')
@patch('gwcelery.tasks.gracedb.remove_label')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment