Skip to content

Commit ffb6f9c

Browse files
committed
TST: take the wall clock out of the shared-deadline test
This branch's CI went red on windows-latest 3.10 with assert min(offered) < 0.05 E assert 0.0500000000001819 < 0.05 The test lives on develop rather than in this branch, and #1182 is where I added it. The stand-in workers return at once, so nothing makes the clock move between _wait_for_the_workers setting its deadline and reading it back for the last of them, and (t + 0.05) - t is not exactly 0.05 in binary. Every other leg passed, and so did the same job on 3.14. The clock is a counter now, so what each worker is offered is decided by arithmetic rather than by how coarse the platform's timer is. The shape the test is about is asserted as well: inside one stage the offers shrink along the fleet, where one deadline each would hand every worker the whole grace. Giving each worker its own grace turns both assertions red and leaves the other twelve in the file green. It sits here because it blocks this pull request's CI, and it is a test-only change to a file this branch does not otherwise touch. Happy to move it to its own pull request if you would rather keep the two apart. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
1 parent 06c172f commit ffb6f9c

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎tests/unit/simulation/test_monte_carlo_worker_join.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from rocketpy.simulation import monte_carlo as mc_module
34
from rocketpy.simulation.monte_carlo import _join_the_workers
45

56

@@ -169,11 +170,18 @@ def test_a_worker_that_ignores_terminate_is_killed():
169170
assert stubborn.killed
170171

171172

172-
def test_the_fleet_comes_down_on_one_deadline_not_one_each():
173+
def test_the_fleet_comes_down_on_one_deadline_not_one_each(monkeypatch):
173174
"""A stage gives the fleet one grace period between them, not each."""
174175
# Observed through what each worker is offered: with a deadline of its own
175176
# every worker is given the whole grace, so a fleet of thirty takes thirty
176177
# times as long to give up on.
178+
#
179+
# The clock ticks by hand. These stand-ins return at once, so a real one
180+
# need not move between setting the deadline and reading it back, and
181+
# Windows measured (t + 0.05) - t as 0.0500000000001819 rather than less.
182+
ticking = iter(index * 0.001 for index in range(100_000))
183+
monkeypatch.setattr(mc_module, "monotonic", lambda: next(ticking))
184+
177185
died = _Worker(exitcode=-9, alive_for=1)
178186
stuck = [_Worker(never=True) for _ in range(4)]
179187

@@ -182,3 +190,9 @@ def test_the_fleet_comes_down_on_one_deadline_not_one_each():
182190
offered = [t for t in stuck[-1].timeouts if t is not None]
183191
assert offered
184192
assert min(offered) < 0.05
193+
194+
# The shape of it: inside one stage the fleet shares what is left, so what
195+
# each worker is offered shrinks along the loop. One deadline each would
196+
# offer every one of them the whole grace.
197+
first, last = died.timeouts[-1], stuck[-1].timeouts[-1]
198+
assert last < first

0 commit comments

Comments
 (0)