Skip to content

Commit a181883

Browse files
committed
src/sage/parallel/map_reduce.py: reduce test dependency on CPU speed
The test we have for start_workers() is doing a bit more than that. It's starting two threads that each print something, sleep for a bit, and then print something else. To check the expected output, we are basically guessing how long it will take these threads to run, and on a very heavily-loaded machine, we can guess wrong: File "src/sage/parallel/map_reduce.py", line 1149, in sage.parallel.map_reduce.RESetMapReduce.start_workers Failed example: sleep(float(1.5)) Expected: Finished: ... Finished: ... Got: Finished: 2 (We were expecting both threads to finish within 1.5s, but only one did.) To make this a bit more robust, we eliminate the sleep() and subsequent print inside of the threads. As a result, we need only make one guess: how long it will take the threads to start. And for that we now go overkill and wait 5s.
1 parent b60d912 commit a181883

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/sage/parallel/map_reduce.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,21 +1136,12 @@ def start_workers(self):
11361136
sage: from sage.parallel.map_reduce import RESetMapReduce
11371137
sage: def children(x):
11381138
....: print(f"Starting: {x}", flush=True)
1139-
....: sleep(float(0.5))
1140-
....: print(f"Finished: {x}", flush=True)
11411139
....: return []
11421140
sage: S = RESetMapReduce(roots=[1, 2], children=children)
11431141
sage: S.setup_workers(2)
1144-
sage: S.start_workers(); sleep(float(0.4))
1142+
sage: S.start_workers(); sleep(float(5)) # long time
11451143
Starting: ...
11461144
Starting: ...
1147-
sage: [w.is_alive() for w in S._workers]
1148-
[True, True]
1149-
sage: sleep(float(1.5))
1150-
Finished: ...
1151-
Finished: ...
1152-
sage: [not w.is_alive() for w in S._workers]
1153-
[True, True]
11541145
11551146
Cleanup::
11561147

0 commit comments

Comments
 (0)