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())
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())