[libgxps] regtest: Limit the number of worker threads to the number of documents to test



commit 81f14f5827731fd28a5bae1fa66ab8ec7a0c54ad
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Tue Jun 23 18:50:47 2015 +0200

    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.

 regtest/TestRun.py |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index ce11fd9..c1f24e6 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -165,21 +165,30 @@ class TestRun:
         docs, total_docs = get_document_paths_from_dir(self._docsdir)
         self._total_tests = total_docs
 
+        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('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...' % (n_workers))
 
-        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)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]