示例#1
0
 def test_set_jobid(self):
     for jobid in (21, 594240, None, -1, "foobar"):
         fut = FluxExecutorFuture(threading.get_ident())
         with self.assertRaises(cf.TimeoutError):
             fut.jobid(timeout=0)
         fut._set_jobid(jobid)
         self.assertEqual(jobid, fut.jobid(timeout=0))
         with self.assertRaises(RuntimeError):
             fut._set_jobid(jobid)
示例#2
0
 def test_multiple_cancel(self):
     fut = FluxExecutorFuture(threading.get_ident())
     invocations = itertools.count()
     fut.add_done_callback(lambda _: next(invocations))
     self.assertFalse(fut.cancelled())
     for _ in range(3):  # test cancelling more than once
         self.assertTrue(fut.cancel())
     self.assertEqual(next(invocations), 1)
     with self.assertRaises(cf.CancelledError):
         fut.jobid()
示例#3
0
 def test_jobid_unavailable(self):
     """Tests for cases where fetching the jobid should raise an exception."""
     fut = FluxExecutorFuture(threading.get_ident())
     fut._set_jobid(None, exc=OverflowError("foobar"))
     with self.assertRaisesRegex(OverflowError, "foobar"):
         fut.jobid(0)
     with self.assertRaises(RuntimeError):
         fut._set_jobid(1)
     # test that jobid raises if future is cancelled
     fut = FluxExecutorFuture(threading.get_ident())
     fut.cancel()
     with self.assertRaises(cf.CancelledError):
         fut.jobid(0)
     # test that jobid doesn't raise if future is cancelled but jobid already set
     fut = FluxExecutorFuture(threading.get_ident())
     jobid = 10
     fut._set_jobid(jobid)
     fut.cancel()
     self.assertEqual(fut.jobid(0), jobid)
     # test that jobid raises if an exception is set before jobid set
     fut = FluxExecutorFuture(threading.get_ident())
     fut.set_exception(ValueError("foobar"))
     with self.assertRaisesRegex(RuntimeError,
                                 r"job could not be submitted.*"):
         fut.jobid()