diff --git a/api/handlers/containerhandler.py b/api/handlers/containerhandler.py index 2ccb3d98ad02818e30af27db5ef3110e3e3b6db2..cf6d76c7f5f41dbbdcca48605f276ee40c1e20b6 100644 --- a/api/handlers/containerhandler.py +++ b/api/handlers/containerhandler.py @@ -271,9 +271,9 @@ class ContainerHandler(base.RequestHandler): # Stateful closure to remove search duplicates # Eventually, this code should not call Queue.search and should instead do its own work. def match_ids(x): - should_add = str(x['_id']) in match_ids.unique_job_ids + in_set = str(x['_id']) in match_ids.unique_job_ids match_ids.unique_job_ids.add(str(x['_id'])) - return should_add + return not in_set match_ids.unique_job_ids = set() results = filter(match_ids, results) diff --git a/test/integration_tests/python/test_jobs.py b/test/integration_tests/python/test_jobs.py index 570ed190e23229b459011e0dd846cb701ef988dc..875296f0645224863aea1f9c67e2d3a033f0fbab 100644 --- a/test/integration_tests/python/test_jobs.py +++ b/test/integration_tests/python/test_jobs.py @@ -21,6 +21,8 @@ def test_jobs_access(as_user): def test_jobs(data_builder, default_payload, as_public, as_user, as_admin, as_root, api_db, file_form): + + # Dupe of test_queue.py gear_doc = default_payload['gear']['gear'] gear_doc['inputs'] = { 'dicom': { diff --git a/test/integration_tests/python/test_queue.py b/test/integration_tests/python/test_queue.py new file mode 100644 index 0000000000000000000000000000000000000000..65e2351bccf4d609eb64721b18622f37c4c5a9ac --- /dev/null +++ b/test/integration_tests/python/test_queue.py @@ -0,0 +1,53 @@ + +def test_queue_search(data_builder, default_payload, as_admin, file_form): + + # Dupe of test_jobs.py + gear_doc = default_payload['gear']['gear'] + gear_doc['inputs'] = { + 'dicom': { + 'base': 'file' + } + } + gear = data_builder.create_gear(gear=gear_doc, category='utility') + project = data_builder.create_project() + session = data_builder.create_session() + acquisition = data_builder.create_acquisition() + assert as_admin.post('/acquisitions/' + acquisition + '/files', files=file_form('test.zip')).ok + + job_data = { + 'gear_id': gear, + 'inputs': { + 'dicom': { + 'type': 'acquisition', + 'id': acquisition, + 'name': 'test.zip' + } + }, + 'config': { 'two-digit multiple of ten': 20 }, + 'destination': { + 'type': 'acquisition', + 'id': acquisition + }, + 'tags': [ 'test-tag' ] + } + + r = as_admin.post('/jobs/add', json=job_data) + assert r.ok + utility_id = r.json()['_id'] + + r = as_admin.get('/sessions/' + session + '/jobs?join=gears') + assert r.ok + assert(any(x['id'] == utility_id for x in r.json()['jobs'])) + + ana_gear_id = data_builder.create_gear(gear=gear_doc, category='analysis') + job_data['gear_id'] = ana_gear_id + + r = as_admin.post('/jobs/add', json=job_data) + assert r.ok + ana_id = r.json()['_id'] + + + r = as_admin.get('/sessions/' + session + '/jobs?join=gears') + assert r.ok + assert(any(x['id'] == utility_id for x in r.json()['jobs'])) + assert(any(x['id'] == ana_id for x in r.json()['jobs']))