Commit 68e58ec5 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

regtest: Limit the number of worker threads to the number of documents to test

We are always spawning all the threads even if the documents to test is
less than the worker threads. Also optimize the case of running only one
test to not spwn any thread.
parent 7c21b958
......@@ -199,22 +199,31 @@ class TestRun:
backends = self._get_backends()
self._total_tests = total_docs * len(backends)
if total_docs == 1:
n_workers = 0
else:
n_workers = min(self.config.threads, total_docs)
self.printer.printout_ln('Found %d documents' % (total_docs))
self.printer.printout_ln('Backends: %s' % ', '.join([backend.get_name() for backend in backends]))
self.printer.printout_ln('Process %d using %d worker threads' % (os.getpid(), self.config.threads))
self.printer.printout_ln('Process %d using %d worker threads' % (os.getpid(), n_workers))
self.printer.printout_ln()
self.printer.printout('Spawning %d workers...' % (self.config.threads))
if n_workers > 0:
self.printer.printout('Spawning %d workers...' % (self.config.threads))
for n_thread in range(self.config.threads):
thread = Thread(target=self._worker_thread)
thread.daemon = True
thread.start()
for n_thread in range(n_workers):
thread = Thread(target=self._worker_thread)
thread.daemon = True
thread.start()
for doc in docs:
self._queue.put(doc)
for doc in docs:
self._queue.put(doc)
self._queue.join()
self._queue.join()
else:
for doc in docs:
self.run_test(doc)
return int(self._n_passed != self._n_run)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment