]> git.ipfire.org Git - pbs.git/commitdiff
tests: Test whether the job queue is functioning okay
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Oct 2022 16:11:50 +0000 (16:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Oct 2022 16:11:50 +0000 (16:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/build.py

index 414d238cf41e4d00b9e084b9d54da3fe4355890e..45541b65951a524320d3494de0b4c9c3049aef8e 100755 (executable)
@@ -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