Skip to content

Commit

Permalink
Test for persistence of future when submitting from a class
Browse files Browse the repository at this point in the history
Motivated the changes to `join` behaviour during `shutdown`
  • Loading branch information
liamhuber committed Nov 9, 2023
1 parent 0079808 commit 8b6e8a6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,40 @@ def submit():
mutable,
msg="After completion, the callback should modify the mutable data"
)

with self.subTest("From inside a class"):
class Foo:
def __init__(self):
self.running = False

def run(self):
self.running = True

future = PyMPISingleTaskExecutor().submit(self.return_42)
future.add_done_callback(self.finished)

return future

def return_42(self):
from time import sleep
sleep(1)
return 42

def finished(self, future):
self.running = False

foo = Foo()
self.assertFalse(
foo.running,
msg="Sanity check that the test starts in the expected condition"
)
fs = foo.run()
self.assertTrue(
foo.running,
msg="We should be able to exit the run method before the task completes"
)
fs.result() # Wait for completion
self.assertFalse(
foo.running,
msg="After task completion, we expect the callback to modify the class"
)

0 comments on commit 8b6e8a6

Please sign in to comment.