import test
from buildservice import builds
+from buildservice import jobs
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