def cancel_on_start(future, jobid): event = future.get_event() if event is None: return if event.name == "shell.start": job.cancel(self.fh, jobid) future.cancel()
def test_15_job_cancel(self): self.sleep_jobspec = JobspecV1.from_command(["sleep", "1000"]) jobid = job.submit(self.fh, self.sleep_jobspec, waitable=True) job.cancel(self.fh, jobid) fut = job.wait_async(self.fh, jobid=jobid).wait_for(5.0) return_id, success, errmsg = fut.get_status() self.assertEqual(return_id, jobid) self.assertFalse(success)
def test_14_job_cancel_invalid_args(self): with self.assertRaises(ValueError): job.kill(self.fh, "abc") with self.assertRaises(ValueError): job.cancel(self.fh, "abc") with self.assertRaises(OSError): job.kill(self.fh, 123) with self.assertRaises(OSError): job.cancel(self.fh, 123)
def test_20_005_job_event_watch_with_cancel(self): jobid = job.submit(self.fh, JobspecV1.from_command(["sleep", "3"]), waitable=True) self.assertTrue(jobid > 0) events = [] future = job.event_watch_async(self.fh, jobid) while True: event = future.get_event() if event is None: break if event.name == "start": future.cancel() events.append(event.name) self.assertEqual(event, None) # Should have less than the expected number of events due to cancel self.assertLess(len(events), 8) job.cancel(self.fh, jobid) job.wait(self.fh, jobid)
def test_20_005_1_job_event_watch_with_cancel_stop_true(self): jobid = job.submit(self.fh, JobspecV1.from_command(["sleep", "3"]), waitable=True) self.assertTrue(jobid > 0) events = [] future = job.event_watch_async(self.fh, jobid) def cb(future, events): event = future.get_event() if event.name == "start": future.cancel(stop=True) events.append(event.name) future.then(cb, events) rc = self.fh.reactor_run() # Last event should be "start" self.assertEqual(events[-1], "start") job.cancel(self.fh, jobid) job.wait(self.fh, jobid)
def test_32_job_result(self): result = {} ids = [] def cb(future, jobid): result[jobid] = future ids.append(job.submit(self.fh, JobspecV1.from_command(["true"]))) ids.append(job.submit(self.fh, JobspecV1.from_command(["false"]))) ids.append(job.submit(self.fh, JobspecV1.from_command(["nosuchprog"]))) ids.append( job.submit(self.fh, JobspecV1.from_command(["sleep", "120"]))) # Submit held job so we can cancel before RUN state ids.append( job.submit(self.fh, JobspecV1.from_command(["true"]), urgency=0)) job.cancel(self.fh, ids[4]) for jobid in ids: flux.job.result_async(self.fh, jobid).then(cb, jobid) def cancel_on_start(future, jobid): event = future.get_event() if event is None: return if event.name == "shell.start": job.cancel(self.fh, jobid) future.cancel() job.event_watch_async(self.fh, ids[3], eventlog="guest.exec.eventlog").then( cancel_on_start, ids[3]) self.fh.reactor_run() self.assertEqual(len(result.keys()), len(ids)) self.addTypeEqualityFunc(JobInfo, self.assertJobInfoEqual) self.assertEqual( result[ids[0]].get_info(), JobInfo({ "id": ids[0], "result": flux.constants.FLUX_JOB_RESULT_COMPLETED, "t_start": 1.0, "t_run": 2.0, "t_cleanup": 3.0, "waitstatus": 0, "exception_occurred": False, }), ) self.assertEqual( result[ids[1]].get_info(), JobInfo({ "id": ids[1], "result": flux.constants.FLUX_JOB_RESULT_FAILED, "t_submit": 1.0, "t_run": 2.0, "t_cleanup": 3.0, "waitstatus": 256, "exception_occurred": False, }), ) self.assertEqual( result[ids[2]].get_info(), JobInfo({ "id": ids[2], "result": flux.constants.FLUX_JOB_RESULT_FAILED, "t_submit": 1.0, "t_run": 2.0, "t_cleanup": 3.0, "waitstatus": 32512, "exception_occurred": True, "exception_type": "exec", "exception_note": "task 0.*: start failed: nosuchprog: " "No such file or directory", "exception_severity": 0, }), ) self.assertEqual( result[ids[3]].get_info(), JobInfo({ "id": ids[3], "result": flux.constants.FLUX_JOB_RESULT_CANCELED, "t_submit": 1.0, "t_run": 2.0, "t_cleanup": 3.0, "waitstatus": 36608, # 143<<8 "exception_occurred": True, "exception_type": "cancel", "exception_note": "", "exception_severity": 0, }), ) self.assertEqual( result[ids[4]].get_info(), JobInfo({ "id": ids[4], "result": flux.constants.FLUX_JOB_RESULT_CANCELED, "t_submit": 0.0, "exception_occurred": True, "exception_type": "cancel", "exception_note": "", "exception_severity": 0, }), ) # synchronous job.result() test self.assertEqual(job.result(self.fh, ids[3]), result[ids[3]].get_info())