Patchwork run-tests: skip threading for a single test (issue5040)

login
register
mail settings
Submitter timeless@mozdev.org
Date Jan. 14, 2016, 4:44 a.m.
Message ID <1c38b20de0cfd66cebd8.1452746698@waste.org>
Download mbox | patch
Permalink /patch/12753/
State Superseded
Commit b04df9ce1fb0591733ae9cbd91208522edfe702c
Headers show

Comments

timeless@mozdev.org - Jan. 14, 2016, 4:44 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1452744890 0
#      Thu Jan 14 04:14:50 2016 +0000
# Node ID 1c38b20de0cfd66cebd881400a7e9c0c197dbe8e
# Parent  5dcadc6c5aed543c0dfaf54890c0b8c19555360a
run-tests: skip threading for a single test (issue5040)

This version backs out 50e621fe0362 and implements it in
a more consistent manner.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1442,6 +1442,8 @@ 
         executes on its own thread. Tests actually spawn new processes, so
         state mutation should not be an issue.
 
+        If there is only one job, it will use the main thread.
+
         whitelist and blacklist denote tests that have been whitelisted and
         blacklisted, respectively. These arguments don't belong in TestSuite.
         Instead, whitelist and blacklist should be handled by the thing that
@@ -1558,45 +1560,44 @@ 
             statthread.start()
 
         try:
-            if len(tests) == 1:
-                test = tests.pop(0)
-                test.run(result)
-            else:
-                while tests or running:
-                    if not done.empty() or running == self._jobs or not tests:
-                        try:
-                            done.get(True, 1)
-                            running -= 1
-                            if result and result.shouldStop:
-                                stoppedearly = True
-                                break
-                        except queue.Empty:
-                            continue
-                    if tests and not running == self._jobs:
-                        test = tests.pop(0)
-                        if self._loop:
-                            if getattr(test, 'should_reload', False):
-                                num_tests[0] += 1
-                                tests.append(
-                                    self._loadtest(test.name, num_tests[0]))
-                            else:
-                                tests.append(test)
+            while tests or running:
+                if not done.empty() or running == self._jobs or not tests:
+                    try:
+                        done.get(True, 1)
+                        running -= 1
+                        if result and result.shouldStop:
+                            stoppedearly = True
+                            break
+                    except queue.Empty:
+                        continue
+                if tests and not running == self._jobs:
+                    test = tests.pop(0)
+                    if self._loop:
+                        if getattr(test, 'should_reload', False):
+                            num_tests[0] += 1
+                            tests.append(
+                                self._loadtest(test.name, num_tests[0]))
+                        else:
+                            tests.append(test)
+                    if self._jobs == 1:
+                        job(test, result)
+                    else:
                         t = threading.Thread(target=job, name=test.name,
                                              args=(test, result))
                         t.start()
-                        running += 1
+                    running += 1
 
-                # If we stop early we still need to wait on started tests to
-                # finish. Otherwise, there is a race between the test completing
-                # and the test's cleanup code running. This could result in the
-                # test reporting incorrect.
-                if stoppedearly:
-                    while running:
-                        try:
-                            done.get(True, 1)
-                            running -= 1
-                        except queue.Empty:
-                            continue
+            # If we stop early we still need to wait on started tests to
+            # finish. Otherwise, there is a race between the test completing
+            # and the test's cleanup code running. This could result in the
+            # test reporting incorrect.
+            if stoppedearly:
+                while running:
+                    try:
+                        done.get(True, 1)
+                        running -= 1
+                    except queue.Empty:
+                        continue
         except KeyboardInterrupt:
             for test in runtests:
                 test.abort()
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -607,6 +607,29 @@ 
 
 #endif
 
+test runs-per-test and loop
+
+  $ mkdir tasks
+  $ echo "  $ touch `pwd`/tasks/\$\$" > test-loop-child.t
+  $ rtt() {
+  >   rm tasks/* 2> /dev/null
+  >   $TESTDIR/run-tests.py -l test-loop-child.t $1 2> /dev/null > /dev/null &
+  >   sleep 1
+  >   kill %1; wait > /dev/null 2> /dev/null
+  >   TASK=`ls tasks | head -1`
+  >   rm tasks/$TASK
+  >   TASK=`ls tasks | head -1`
+  >   rm tasks/* 2> /dev/null
+  >   touch tasks/$TASK
+  > }
+  $ rtt --runs-per-test=200
+  $ ls tasks
+  * (glob)
+  $ rtt --loop
+  $ ls tasks
+  * (glob)
+  $ rm -rf tasks
+
 backslash on end of line with glob matching is handled properly
 
   $ cat > test-glob-backslash.t << EOF