From: Michael Tremer Date: Mon, 24 Oct 2022 16:11:50 +0000 (+0000) Subject: tests: Test whether the job queue is functioning okay X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c045fe376af794eec48e8ddbee00f5aaadbebc64;p=pbs.git tests: Test whether the job queue is functioning okay Signed-off-by: Michael Tremer --- diff --git a/tests/build.py b/tests/build.py index 414d238c..45541b65 100755 --- a/tests/build.py +++ b/tests/build.py @@ -6,6 +6,7 @@ import unittest import test from buildservice import builds +from buildservice import jobs class BuildTestCase(test.TestCase): """ @@ -72,6 +73,57 @@ class BuildTestCase(test.TestCase): # But we should be able to fetch the build by its ID self.assertEqual(self.backend.builds.get_by_id(build.id), build) + async def test_queue(self): + """ + Check if all jobs appear correctly in the queue + """ + path = self.source_path("tests/data/beep-1.3-2.ip3.src.pfm") + + # Create the build + with self.db.transaction(): + build = await self._create_build(path, owner=self.user) + + # Fetch jobs + job1, job2 = build.jobs + + self.assertIsInstance(job1, jobs.Job) + self.assertIsInstance(job2, jobs.Job) + + # There should be no jobs in the queue yet, because the dependency check + # has not been finished, yet + self.assertEqual(len(self.backend.jobqueue), 0) + + # Pretend the dependency check was successful + for job in build.jobs: + job._set_attribute("depcheck_succeeded", True) + + # There should now be two jobs in the queue + self.assertEqual(len(self.backend.jobqueue), 2) + + # Assign a job to a builder + job1.assign(self.builder) + + # There should be one job left + self.assertEqual(len(self.backend.jobqueue), 1) + + # Let the job fail + await job1.finished(success=False) + + # There should still be only one job + self.assertEqual(len(self.backend.jobqueue), 1) + + # Assign the second job + job2.assign(self.builder) + + # The queue should now be empty + self.assertEqual(len(self.backend.jobqueue), 0) + + # Pretend the job finished successfully + await job2.finished(success=True) + + # The queue should still be empty + self.assertEqual(len(self.backend.jobqueue), 0) + async def test_watchers(self): """ Tests whether we can add and remove a watcher to a build