def test_also_after_suspend_manual_flag(self): # Define a job job = make_job("A", summary="foo", flags='also-after-suspend-manual') # Define an empty session session = SessionState([]) # Add the job to the session session.add_unit(job) # Both jobs got added to job list self.assertEqual(len(session.job_list), 2) self.assertIn(job, session.job_list) self.assertEqual(session.job_list[1].id, 'after-suspend-manual-A') self.assertEqual(session.job_list[1].summary, 'foo after suspend (S3)') self.assertEqual( session.job_list[1].depends, 'A com.canonical.certification::suspend/suspend_advanced') sibling = session.job_list[1] self.assertNotIn('also-after-suspend-manual', sibling.get_flag_set()) # Both jobs got added to job state map self.assertIs(session.job_state_map[job.id].job, job) self.assertIs(session.job_state_map[sibling.id].job, sibling) # Both jobs are not added to the desired job list self.assertNotIn(job, session.desired_job_list) self.assertNotIn(sibling, session.desired_job_list) # Both jobs are not in the run list self.assertNotIn(job, session.run_list) self.assertNotIn(sibling, session.run_list) # Both jobs are not selected to run self.assertEqual( session.job_state_map[job.id].readiness_inhibitor_list, [UndesiredJobReadinessInhibitor]) self.assertEqual( session.job_state_map[sibling.id].readiness_inhibitor_list, [UndesiredJobReadinessInhibitor])
def test_add_sibling_unit(self): # Define a job job = make_job("A", summary="foo", siblings='[{"id": "B"}]') # Define an empty session session = SessionState([]) # Add the job to the session session.add_unit(job) # Both jobs got added to job list self.assertEqual(len(session.job_list), 2) self.assertIn(job, session.job_list) self.assertEqual(session.job_list[1].id, 'B') self.assertEqual(session.job_list[1].summary, 'foo') sibling = session.job_list[1] # Both jobs got added to job state map self.assertIs(session.job_state_map[job.id].job, job) self.assertIs(session.job_state_map[sibling.id].job, sibling) # Both jobs are not added to the desired job list self.assertNotIn(job, session.desired_job_list) self.assertNotIn(sibling, session.desired_job_list) # Both jobs are not in the run list self.assertNotIn(job, session.run_list) self.assertNotIn(sibling, session.run_list) # Both jobs are not selected to run self.assertEqual( session.job_state_map[job.id].readiness_inhibitor_list, [UndesiredJobReadinessInhibitor]) self.assertEqual( session.job_state_map[sibling.id].readiness_inhibitor_list, [UndesiredJobReadinessInhibitor])
def test_add_unit(self): # Define a job job = make_job("A") # Define an empty session session = SessionState([]) # Add the job to the session session.add_unit(job) # The job got added to job list self.assertIn(job, session.job_list) # The job got added to job state map self.assertIs(session.job_state_map[job.id].job, job) # The job is not added to the desired job list self.assertNotIn(job, session.desired_job_list) # The job is not in the run list self.assertNotIn(job, session.run_list) # The job is not selected to run self.assertEqual( session.job_state_map[job.id].readiness_inhibitor_list, [UndesiredJobReadinessInhibitor])
def test_add_unit_duplicate_job(self): # Define a job job = make_job("A") # Define an empty session session = SessionState([]) # Add the job to the session session.add_unit(job) # The job got added to job list self.assertIn(job, session.job_list) # Define a perfectly identical job duplicate_job = make_job("A") self.assertEqual(job, duplicate_job) # Try adding it to the session # # Note that this does not raise any exceptions as the jobs are perfect # duplicates. session.add_unit(duplicate_job) # The new job _did not_ get added to the job list self.assertEqual(len(session.job_list), 1) self.assertIsNot(duplicate_job, session.job_list[0])
def test_add_unit_clashing_job(self): # Define a job job = make_job("A") # Define an empty session session = SessionState([]) # Add the job to the session session.add_unit(job) # The job got added to job list self.assertIn(job, session.job_list) # Define a different job that clashes with the initial job clashing_job = make_job("A", plugin='other') self.assertNotEqual(job, clashing_job) self.assertEqual(job.id, clashing_job.id) # Try adding it to the session # # This raises an exception with self.assertRaises(DependencyDuplicateError) as call: session.add_unit(clashing_job) # The exception gets job in the right order self.assertIs(call.exception.affected_job, job) self.assertIs(call.exception.affecting_job, clashing_job) # The new job _did not_ get added to the job list self.assertEqual(len(session.job_list), 1) self.assertIsNot(clashing_job, session.job_list[0])