def _run_tests(self, test_queue, setup_flag, teardown_flag):
|
"""Start a thread for each Job instance and block until all of the tests are run.
|
Returns a (combined report, user interrupted) pair, where the
|
report contains the status and timing information of tests run
|
by all of the threads.
|
"""
|
|
threads = []
|
interrupt_flag = threading.Event()
|
user_interrupted = False
|
try:
|
# Run each Job instance in its own thread.
|
for job in self._jobs:
|
thr = threading.Thread(
|
target=job, args=(test_queue, interrupt_flag), kwargs=dict(
|
setup_flag=setup_flag, teardown_flag=teardown_flag))
|
# Do not wait for tests to finish executing if interrupted by the user.
|
thr.daemon = True
|
thr.start()
|
threads.append(thr)
|
# SERVER-24729 Need to stagger when jobs start to reduce I/O load if there
|
# are many of them. Both the 5 and the 10 are arbitrary.
|
# Currently only enabled on Evergreen.
|
if _config.STAGGER_JOBS and len(threads) >= 5:
|
time.sleep(10)
|
|
joined = False
|
while not joined:
|
# Need to pass a timeout to join() so that KeyboardInterrupt exceptions
|
# are propagated.
|
joined = test_queue.join(TestSuiteExecutor._TIMEOUT)
|
except (KeyboardInterrupt, SystemExit):
|
interrupt_flag.set()
|
user_interrupted = True
|
else:
|
# Only wait for all the Job instances if not interrupted by the user.
|
self.logger.debug("Waiting for threads to complete")
|
for thr in threads:
|
thr.join()
|
self.logger.debug("Threads are completed!")
|