diff --git a/doc/ci.rst b/doc/ci.rst index a4462f8a..19ea616b 100644 --- a/doc/ci.rst +++ b/doc/ci.rst @@ -89,8 +89,10 @@ Submitting test job watch requests Test job watch request are similar to test job requests. The only difference is that some other service submitted the test job for execution and SQUAD is -requested to track the progress. After test job is finished SQUAD will retrieve -the results and do post processing. The API is following: +requested to track the progress. By default, SQUAD will schedule the job +for fetching right away. If the variable `?delay_fetch` is present, SQUAD will +wait until the test job is finished before retrieving the results and do post +processing. The API is following: **POST** /api/watchjob/:group/:project/:build/:environment diff --git a/squad/api/ci.py b/squad/api/ci.py index 52475301..34b3395f 100644 --- a/squad/api/ci.py +++ b/squad/api/ci.py @@ -117,8 +117,10 @@ def watch_job(request, group_slug, project_slug, version, environment_slug): log_addition(request, test_job, "Watch Job submission") - # schedule a fetch task on this job right away - fetch.delay(test_job.id) + delay_fetch = request.GET.get("delay_fetch") + if delay_fetch is None: + # schedule a fetch task on this job right away + fetch.delay(test_job.id) # return ID of test job return HttpResponse(test_job.id, status=201) diff --git a/test/api/test_ci.py b/test/api/test_ci.py index ba7455f1..6ee36946 100644 --- a/test/api/test_ci.py +++ b/test/api/test_ci.py @@ -252,6 +252,41 @@ def test_watch_testjob(self, fetch): logentry_queryset.last().action_flag ) + @patch("squad.ci.tasks.fetch.delay") + def test_watch_testjob_do_not_fetch_rightaway(self, fetch): + testjob_id = 1234 + args = { + 'backend': 'lava', + 'testjob_id': testjob_id, + } + r = self.client.post('/api/watchjob/mygroup/myproject/1/myenv?delay_fetch', args) + self.assertEqual(201, r.status_code) + testjob_queryset = models.TestJob.objects.filter( + target=self.project, + environment='myenv', + target_build=self.build, + backend=self.backend, + submitted=True, + job_id=testjob_id + ) + self.assertEqual( + 1, + testjob_queryset.count() + ) + fetch.assert_not_called() + logentry_queryset = LogEntry.objects.filter( + user_id=self.project_privileged_user.pk, + object_id=testjob_queryset.last().pk + ) + self.assertEqual( + 1, + logentry_queryset.count() + ) + self.assertEqual( + ADDITION, + logentry_queryset.last().action_flag + ) + @patch("squad.ci.tasks.fetch.apply_async") def test_watch_testjob_private_group(self, fetch): testjob_id = 1234