Exemple #1
0
 def test_callback_deadlock(self):
     flag = threading.Event()
     # try waiting for the future from the callback
     fut = FluxExecutorFuture(threading.get_ident()).add_jobid_callback(
         lambda fut: (fut.result(), flag.set())
     )
     fut._set_jobid(5)
     # check that flag wasn't set---because the callback raised
     self.assertFalse(flag.is_set())
     # try the same with an event callback
     log_event = EventLogEvent({"name": "debug", "timestamp": 0})
     fut.add_event_callback(
         log_event.name, lambda fut, event: (fut.result(), flag.set())
     )
     fut._set_event(log_event)
     self.assertFalse(flag.is_set())
     # now complete the future and try again
     fut.set_result(21)
     fut.add_jobid_callback(lambda fut: (fut.result(), flag.set()))
     self.assertTrue(flag.is_set())
     flag.clear()
     fut.add_event_callback(
         log_event.name, lambda fut, event: (fut.result(), flag.set())
     )
     self.assertTrue(flag.is_set())
Exemple #2
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)
Exemple #3
0
 def test_jobid_callback(self):
     fut = FluxExecutorFuture(threading.get_ident())
     flag = threading.Event()
     fut.add_jobid_callback(lambda f: flag.set())
     self.assertFalse(flag.is_set())
     fut._set_jobid(5)
     self.assertTrue(flag.is_set())
     # now check that adding callbacks fires them immediately
     flag.clear()
     fut.add_jobid_callback(lambda f: flag.set())
     self.assertTrue(flag.is_set())
Exemple #4
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()