Skip to content

Commit c467ec2

Browse files
committed
Partial Revert "Fix JobTests.py"
This reverts commit d932ba3.
1 parent 42ddab2 commit c467ec2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

SCons/Taskmaster/JobTests.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,50 @@ def runTest(self):
285285
self.assertFalse(taskmaster.num_failed,
286286
"some task(s) failed to execute")
287287

288+
# Verify that parallel jobs will pull all of the completed tasks
289+
# out of the queue at once, instead of one by one. We do this by
290+
# replacing the default ThreadPool class with one that records the
291+
# order in which tasks are put() and get() to/from the pool, and
292+
# which sleeps a little bit before call get() to let the initial
293+
# tasks complete and get their notifications on the resultsQueue.
294+
295+
class SleepTask(Task):
296+
def _do_something(self) -> None:
297+
time.sleep(0.01)
298+
299+
global SaveThreadPool
300+
SaveThreadPool = SCons.Taskmaster.Job.ThreadPool
301+
302+
class WaitThreadPool(SaveThreadPool):
303+
def put(self, task):
304+
ThreadPoolCallList.append('put(%s)' % task.i)
305+
return SaveThreadPool.put(self, task)
306+
def get(self):
307+
time.sleep(0.05)
308+
result = SaveThreadPool.get(self)
309+
ThreadPoolCallList.append('get(%s)' % result[0].i)
310+
return result
311+
312+
SCons.Taskmaster.Job.ThreadPool = WaitThreadPool
313+
314+
try:
315+
taskmaster = Taskmaster(3, self, SleepTask)
316+
jobs = SCons.Taskmaster.Job.Jobs(2, taskmaster)
317+
jobs.run()
318+
319+
# The key here is that we get(1) and get(2) from the
320+
# resultsQueue before we put(3), but get(1) and get(2) can
321+
# be in either order depending on how the first two parallel
322+
# tasks get scheduled by the operating system.
323+
expect = [
324+
['put(1)', 'put(2)', 'get(1)', 'get(2)', 'put(3)', 'get(3)'],
325+
['put(1)', 'put(2)', 'get(2)', 'get(1)', 'put(3)', 'get(3)'],
326+
]
327+
assert ThreadPoolCallList in expect, ThreadPoolCallList
328+
329+
finally:
330+
SCons.Taskmaster.Job.ThreadPool = SaveThreadPool
331+
288332
class SerialTestCase(unittest.TestCase):
289333
def runTest(self) -> None:
290334
"""test a serial job"""

0 commit comments

Comments
 (0)