Skip to content

Commit

Permalink
Fix race condition in unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoo committed Feb 3, 2015
1 parent ba31bb0 commit 002cc33
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/tasks/test_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ def test_execute_async(self):

# Verify exception path
self.task.fail_async = True
f = self.task.execute_async()
with self.assertRaises(Exception) as ctx:
f.result()
# Call this twice, since there's a race condition where setting
# fail_async and getting the future from execute_async is called
# when execute is between the self.fail_async check and the return
self.task.execute_async().result(1.0)
self.task.execute_async().result(1.0)

self.assertEqual(ctx.exception.args[0], "fail_async")

# Wait until task shuts down
Expand Down

0 comments on commit 002cc33

Please sign in to comment.