tests: align closed-owner semantics; route moving-body checks in state regressions
test_failed_moving_step_marks_simulation_failed uses an owner double that refuses activation after close like CudaContext and expects 'CUDA context is closed'; test_passive_overlap_failure_keeps_live_state binds the real moving-body validation methods and a stepper double. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e1ed27b438
commit
983020b625
@@ -94,7 +94,15 @@ def test_refill_donor_sets_nonempty_within_bounds(radius):
|
||||
|
||||
pytest.importorskip("pycuda.driver")
|
||||
from CelerisLab import simulation as module # noqa: E402
|
||||
from tests.unit.test_simulation_lifecycle import make_simulation # noqa: E402
|
||||
from tests.unit.test_simulation_lifecycle import Owner, make_simulation # noqa: E402
|
||||
|
||||
|
||||
class ClosableOwner(Owner):
|
||||
"""Owner double that refuses activation after close, like CudaContext.activate."""
|
||||
def activate(self):
|
||||
if self.is_closed:
|
||||
raise RuntimeError("CUDA context is closed")
|
||||
return super().activate()
|
||||
|
||||
|
||||
def moving_simulation(monkeypatch, *, moving=True):
|
||||
@@ -316,6 +324,7 @@ def test_moving_circle_excluded_from_static_links():
|
||||
|
||||
def test_failed_moving_step_marks_simulation_failed(monkeypatch):
|
||||
sim = routed_simulation(monkeypatch)
|
||||
sim.ctx = ClosableOwner()
|
||||
bid = sim.add_body("circle", (50., 40.), 10., translation=Translation((0., 0., -1., 1.), .1))
|
||||
motion = sim.bodies.get(bid).motion
|
||||
motion.set_target((0., .2), (0., .05))
|
||||
@@ -337,5 +346,7 @@ def test_failed_moving_step_marks_simulation_failed(monkeypatch):
|
||||
assert sim._failed is not None and sim.bodies is not None and not sim._closed
|
||||
sim.close() # retry outside the activation succeeds
|
||||
assert sim._closed and sim._failed is not None
|
||||
with pytest.raises(RuntimeError, match="Simulation failed"): # no re-entry after close
|
||||
with pytest.raises(RuntimeError, match="CUDA context is closed"): # no re-entry after close
|
||||
sim.run(1)
|
||||
with pytest.raises(RuntimeError, match="unknown"): # the failed circle stays refused
|
||||
motion.record()
|
||||
|
||||
@@ -294,8 +294,11 @@ def test_passive_overlap_failure_keeps_live_state(device, entry, second_x):
|
||||
sim = SimpleNamespace(bodies=bodies, field=field, lbm_cfg=field.cfg,
|
||||
_initialized=entry == "runtime_edit",
|
||||
_assert_allocation_contract=lambda: None,
|
||||
stream=SimpleNamespace(synchronize=device.synchronize))
|
||||
sim._require_usable = Simulation._require_usable.__get__(sim)
|
||||
stream=SimpleNamespace(synchronize=device.synchronize),
|
||||
stepper=SimpleNamespace(blocked=None))
|
||||
for name in ("_require_usable", "_moving_bodies", "_reject_moving_bodies",
|
||||
"_validate_moving_bodies"):
|
||||
setattr(sim, name, getattr(Simulation, name).__get__(sim))
|
||||
with pytest.raises(ValueError, match="active fluid receivers|unique cut-link writers"):
|
||||
if entry == "sync":
|
||||
bodies.sync_to_gpu(field)
|
||||
|
||||
Reference in New Issue
Block a user