Skip to content

Commit

Permalink
Fix race condition in test case
Browse files Browse the repository at this point in the history
Make sure that all threads have been executed before checking assertion
  • Loading branch information
Javier Collado committed Jan 18, 2017
1 parent 700dd8b commit a4a4550
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rabbithole/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ def run_input_blocks(namespace):
:type namespace: dict(str, instance)
"""
threads = []
for block_name, block_instance in six.iteritems(namespace):
run_method = getattr(block_instance, 'run', None)
if run_method:
thread = threading.Thread(name=block_name, target=run_method)
thread.daemon = True
thread.start()
threads.append(thread)

return threads


def parse_arguments(argv):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def test_run_method_called(self):
namespace = {
'<name>': block_instance,
}
run_input_blocks(namespace)
threads = run_input_blocks(namespace)
for thread in threads:
thread.join()
block_instance.run.assert_called_once_with()


Expand Down

0 comments on commit a4a4550

Please sign in to comment.