From 72729a5a0f4749125f8884076cdef4d3f5b542b0 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Fri, 2 Aug 2024 13:42:24 +0200 Subject: [PATCH] fix: Ensure ODD cleanup if sequencer stops in Examples Python tests --- Examples/Python/tests/conftest.py | 9 ++- Examples/Python/tests/test_examples.py | 83 +++++++++++++++++------ Examples/Python/tests/test_propagation.py | 9 ++- Examples/Python/tests/test_reader.py | 16 ++++- Examples/Python/tests/test_writer.py | 8 ++- 5 files changed, 101 insertions(+), 24 deletions(-) diff --git a/Examples/Python/tests/conftest.py b/Examples/Python/tests/conftest.py index b288b51f9b3..1615e153083 100644 --- a/Examples/Python/tests/conftest.py +++ b/Examples/Python/tests/conftest.py @@ -374,7 +374,14 @@ def _do_material_recording(d: Path): s = acts.examples.Sequencer(events=2, numThreads=1) runMaterialRecording(detectorConstructionFactory, str(d), tracksPerEvent=100, s=s) - s.run() + + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s @pytest.fixture(scope="session") diff --git a/Examples/Python/tests/test_examples.py b/Examples/Python/tests/test_examples.py index 8cfe4fb5abd..9f65c377889 100644 --- a/Examples/Python/tests/test_examples.py +++ b/Examples/Python/tests/test_examples.py @@ -520,7 +520,13 @@ def test_event_recording(tmp_path): ) s.addAlgorithm(alg) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert alg.events_seen == 1 @@ -713,11 +719,13 @@ def test_material_mapping(material_recording, tmp_path, assert_root_hash): s=s, ) - s.run() - - # MaterialMapping alg only writes on destruct. - # See https://github.com/acts-project/acts/issues/881 - del s + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s mat_file = tmp_path / "material-map.json" @@ -754,7 +762,13 @@ def test_material_mapping(material_recording, tmp_path, assert_root_hash): 10, 1000, trackingGeometry, decorators, field, outputDir=str(tmp_path), s=s ) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert val_file.exists() assert_entries(val_file, "material-tracks", 10000) @@ -792,11 +806,13 @@ def test_volume_material_mapping(material_recording, tmp_path, assert_root_hash) s=s, ) - s.run() - - # MaterialMapping alg only writes on destruct. - # See https://github.com/acts-project/acts/issues/881 - del s + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s mat_file = tmp_path / "material-map-volume.json" @@ -840,7 +856,13 @@ def test_volume_material_mapping(material_recording, tmp_path, assert_root_hash) s=s, ) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert val_file.exists() assert_root_hash(val_file.name, val_file) @@ -947,7 +969,13 @@ def test_digitization_example(trk_geo, tmp_path, assert_root_hash, digi_config_f trk_geo, field, outputDir=tmp_path, digiConfigFile=digi_config_file, s=s ) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert root_file.exists() assert csv_dir.exists() @@ -976,7 +1004,14 @@ def test_digitization_example_input( ptcl_dir.mkdir() pgs = Sequencer(events=20, numThreads=-1) runParticleGun(str(ptcl_dir), s=pgs) - pgs.run() + + try: + pgs.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s s = Sequencer(numThreads=-1) @@ -1002,7 +1037,13 @@ def test_digitization_example_input( doMerge=True, ) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert root_file.exists() assert csv_dir.exists() @@ -1102,9 +1143,13 @@ def test_ckf_tracks_example( s=s, ) - s.run() - - del s # files are closed in destructors, not great + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert csv.exists() for rf, tn in root_files: diff --git a/Examples/Python/tests/test_propagation.py b/Examples/Python/tests/test_propagation.py index fdd03cca688..491992da66e 100644 --- a/Examples/Python/tests/test_propagation.py +++ b/Examples/Python/tests/test_propagation.py @@ -64,6 +64,13 @@ def test_steppers(conf_const, trk_geo): "propagation_steps", "chk_alg", level=acts.logging.WARNING ) seq.addAlgorithm(chkAlg) - seq.run() + + try: + seq.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert acts.StraightLineStepper() diff --git a/Examples/Python/tests/test_reader.py b/Examples/Python/tests/test_reader.py index e7bae0b9721..ac2f6e3a521 100644 --- a/Examples/Python/tests/test_reader.py +++ b/Examples/Python/tests/test_reader.py @@ -155,7 +155,13 @@ def test_root_material_track_reader(material_recording): ) s.addAlgorithm(alg) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert alg.events_seen == 2 @@ -331,7 +337,13 @@ def test_edm4hep_simhit_particle_reader(tmp_path): ) s.addAlgorithm(alg) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s assert alg.events_seen == 10 diff --git a/Examples/Python/tests/test_writer.py b/Examples/Python/tests/test_writer.py index 18dac96e96f..df64ed6a71a 100644 --- a/Examples/Python/tests/test_writer.py +++ b/Examples/Python/tests/test_writer.py @@ -482,7 +482,13 @@ def test_hepmc3_histogram(hepmc_data, tmp_path): ) s.addAlgorithm(alg) - s.run() + try: + s.run() + finally: + # make sure to clean up if the test fails (otherwise segfault with ODD) + # also + # files are closed in destructors, not great + del s @pytest.mark.edm4hep