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_finish_completion(self): thread = _FluxExecutorThread( threading.Event(), collections.deque(), 0.01, (), {} ) for exit_status in (0, 1, 15, 120, 255): flag = threading.Event() fut = FluxExecutorFuture(threading.get_ident()).add_done_callback( lambda fut: flag.set() ) thread._FluxExecutorThread__event_update( ShamJobEventWatchFuture( EventLogEvent( { "name": "finish", "timestamp": 0, "context": {"status": exit_status}, } ) ), fut, ) self.assertTrue(fut.done()) self.assertTrue(flag.is_set()) if os.WIFEXITED(exit_status): self.assertEqual(fut.result(), os.WEXITSTATUS(exit_status)) elif os.WIFSIGNALED(exit_status): self.assertEqual(fut.result(), -os.WTERMSIG(exit_status))