def test_run_cancel(self):
     with test_utils.RecipeDir() as recipe_dir:
         c, job = self.create_client_and_job(recipe_dir, "Cancel", sleep=4)
         self.set_counts()
         c.client_info["single_shot"] = False
         c.client_info["poll"] = 1
         # cancel signal, should stop
         script = "sleep 3 && kill -USR1 %s" % os.getpid()
         proc = subprocess.Popen(script,
                                 shell=True,
                                 executable="/bin/bash",
                                 stdout=subprocess.PIPE)
         c.run()
         proc.wait()
         self.compare_counts(
             canceled=1,
             num_clients=1,
             num_events_completed=1,
             num_jobs_completed=1,
             active_branches=1,
             events_canceled=1,
         )
         self.assertEqual(c.cancel_signal.triggered, True)
         self.assertEqual(c.graceful_signal.triggered, False)
         utils.check_canceled_job(self, job, c)
Beispiel #2
0
 def test_run_job_cancel(self):
     with test_utils.RecipeDir() as recipe_dir:
         c, job = self.create_client_and_job(recipe_dir, "JobCancel", sleep=4)
         self.set_counts()
         # cancel response, should cancel the job
         thread = threading.Thread(target=c.run, args=(True,))
         thread.start()
         time.sleep(4)
         job.refresh_from_db()
         views.set_job_canceled(job)
         thread.join()
         self.compare_counts(num_clients=1, canceled=1, num_events_completed=1, num_jobs_completed=1, active_branches=1, events_canceled=1)
         self.assertEqual(c.cancel_signal.triggered, False)
         self.assertEqual(c.graceful_signal.triggered, False)
         utils.check_canceled_job(self, job)