Skip to content

Commit 867f762

Browse files
authored
Merge pull request SCons#3104 from dmoody256/JobsTestsParallelFix
JobTests.py parallel issue fix
2 parents a1a453e + fd6d431 commit 867f762

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

.travis.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ jobs:
1414
include:
1515
- &test_job
1616
stage: Test
17-
script:
18-
# WORKAROUND: attempt to retry JobTests.py if it fails and then continue if it passes, if it fails ten times
19-
# then it is a real failure not related to intermittent travis failures
20-
- n=0; while [[ $n -lt 10 ]]; do python runtest.py src/engine/SCons/JobTests.py && break; n=$((n+1)); done; if [ "$n" -gt "9" ]; then false; fi
21-
- echo "src/engine/SCons/JobTests.py" > exclude_jobtest
22-
- python runtest.py -a --exclude-list exclude_jobtest || if [[ $? == 2 ]]; then true; else false; fi
17+
script: python runtest.py -a || if [[ $? == 2 ]]; then true; else false; fi
2318
before_script: skip
2419
after_success: skip
2520
python: 2.7
@@ -71,14 +66,8 @@ jobs:
7166
- echo "parallel = True" >> .coveragerc
7267
- printf "omit =\n\t*Tests.py\n\tsrc/test_*\n\tsrc/setup.py\n\n" >> .coveragerc
7368
- echo "[path] = $PWD" >> .coveragerc
74-
# Not including this workaround in the coverage report, because it will result
75-
# in constantly changing coverage reports depending on the number of times
76-
# the JobTests.py had to run to pass
77-
# TODO: figure out how to cover JobTests.py
78-
# - n=0; while [[ $n -lt 10 ]]; do coverage run --rcfile=$PWD/.coveragerc runtest.py src/engine/SCons/JobTests.py && break; n=$((n+1)); done; if [ "$n" -gt "9" ]; then false; fi
79-
# exclude JobTest.py becuase we already ran that
80-
- echo "src/engine/SCons/JobTests.py" > exclude_jobtest
81-
- python runtest.py -l -a --exclude-list exclude_jobtest > all_tests
69+
# get a list of all the tests to split them up
70+
- python runtest.py -l -a > all_tests
8271
- let "start = ($(wc -l < all_tests) / ${TOTAL_BUILD_JOBS}) * (${BUILD_JOB_NUM} - 1)"; true;
8372
- let "end = ($(wc -l < all_tests) / ${TOTAL_BUILD_JOBS}) * ${BUILD_JOB_NUM}"
8473
- if (( ${BUILD_JOB_NUM} == ${TOTAL_BUILD_JOBS} )); then end=$(wc -l < all_tests); fi

src/engine/SCons/JobTests.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_cpu_nums():
5252
return 1 # Default
5353

5454
# a large number
55-
num_sines = 10000
55+
num_sines = 500
5656

5757
# how many parallel jobs to perform for the test
5858
num_jobs = get_cpu_nums()*2
@@ -105,7 +105,17 @@ def execute(self):
105105
self.taskmaster.begin_list.append(self.i)
106106
self.taskmaster.guard.release()
107107

108+
# while task is executing, represent this in the parallel_list
109+
# and then turn it off
110+
self.taskmaster.parallel_list[self.i] = 1
108111
self._do_something()
112+
self.taskmaster.parallel_list[self.i] = 0
113+
114+
# check if task was executing while another was also executing
115+
for j in range(1, self.taskmaster.num_tasks):
116+
if(self.taskmaster.parallel_list[j+1] == 1):
117+
self.taskmaster.found_parallel = True
118+
break
109119

110120
self.was_executed = 1
111121

@@ -132,10 +142,13 @@ def failed(self):
132142
def postprocess(self):
133143
self.taskmaster.num_postprocessed = self.taskmaster.num_postprocessed + 1
134144

145+
def exception_set(self):
146+
pass
147+
135148
class RandomTask(Task):
136149
def _do_something(self):
137150
# do something that will take some random amount of time:
138-
for i in range(random.randrange(0, num_sines, 1)):
151+
for i in range(random.randrange(0, 100 + num_sines, 1)):
139152
x = math.sin(i)
140153
time.sleep(0.01)
141154

@@ -190,7 +203,10 @@ def __init__(self, n, test_case, Task):
190203
self.num_executed = 0
191204
self.num_failed = 0
192205
self.num_postprocessed = 0
206+
self.parallel_list = [0] * (n+1)
207+
self.found_parallel = False
193208
self.Task = Task
209+
194210
# 'guard' guards 'task_begin_list' and 'task_end_list'
195211
try:
196212
import threading
@@ -222,12 +238,7 @@ def all_tasks_are_postprocessed(self):
222238

223239
def tasks_were_serial(self):
224240
"analyze the task order to see if they were serial"
225-
serial = 1 # assume the tasks were serial
226-
for i in range(num_tasks):
227-
serial = serial and (self.begin_list[i]
228-
== self.end_list[i]
229-
== (i + 1))
230-
return serial
241+
return not self.found_parallel
231242

232243
def exception_set(self):
233244
pass
@@ -271,7 +282,7 @@ def runTest(self):
271282

272283
class SleepTask(Task):
273284
def _do_something(self):
274-
time.sleep(0.1)
285+
time.sleep(0.01)
275286

276287
global SaveThreadPool
277288
SaveThreadPool = SCons.Job.ThreadPool
@@ -281,7 +292,7 @@ def put(self, task):
281292
ThreadPoolCallList.append('put(%s)' % task.i)
282293
return SaveThreadPool.put(self, task)
283294
def get(self):
284-
time.sleep(0.5)
295+
time.sleep(0.05)
285296
result = SaveThreadPool.get(self)
286297
ThreadPoolCallList.append('get(%s)' % result[0].i)
287298
return result

0 commit comments

Comments
 (0)