diff --git a/tests/unit/test_moving_bodies.py b/tests/unit/test_moving_bodies.py index f90c725..f5b2814 100644 --- a/tests/unit/test_moving_bodies.py +++ b/tests/unit/test_moving_bodies.py @@ -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() diff --git a/tests/unit/test_state_regressions.py b/tests/unit/test_state_regressions.py index 2e9f32a..f7b1ff7 100644 --- a/tests/unit/test_state_regressions.py +++ b/tests/unit/test_state_regressions.py @@ -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)