Simplify test process clean-up
Melissa DA may leave running processes behind after the end of a test. Attempts are made to identify and kill these residual processes but this is done manually for every test. Examples:
# Should be the last test!
add_python_test("test-cleanup"
"${CMAKE_CURRENT_SOURCE_DIR}/test-cleanup.py")
if sys.argv[1] == 'test-example-simulation2':
LocalCluster.clean_up_test()
run()
LocalCluster.clean_up_test()
CMake test fixtures are commands that are executed before or after tests even if the test failed or if only a subset of tests are to be executed. The following example is based on an example from the CMake 3.7 documentation and shows how a database can be put into a well-defined state before different tests are run:
add_test(NAME dbOnly COMMAND testDb)
add_test(NAME createDB COMMAND initDB)
add_test(NAME cleanupDB COMMAND deleteDB)
set_tests_properties(createDB PROPERTIES FIXTURES_SETUP DB)
set_tests_properties(cleanupDB PROPERTIES FIXTURES_CLEANUP DB)
set_tests_properties(dbOnly PROPERTIES FIXTURES_REQUIRED DB)
set_tests_properties(dbOnly createDB cleanupDB
PROPERTIES RESOURCE_LOCK DbAccess)
In the context of this issue, the manual process management would be replaced by CMake test fixtures. Future tests would directly benefit from the changes. Furthermore, each test would be modified to lock the Melissa launcher port resource (see RESOURCE_LOCK
above) because every test runs the Melissa launcher listening on the same port. This way parallel test execution would not cause test failures any more. (Parallel test execution refer to the execution of ctest --parallel <N>
, not to the actual test execution.)
Key changes:
-
set RESOURCE_LOCK
test property inadd_python_test
-
set FIXTURES_REQUIRED
test property inadd_python_test
-
remove repeated calls to LocalCluster.clean_up_test()
andmelissa-da-cleanup-local.sh
with test fixtures