From 76b6959cadbfa811fff9c6f129c4e91270bbb2b2 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 8 Mar 2021 22:11:47 +0100 Subject: [PATCH] Fix parallel build race condition for test targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When executing “make test -jX” (with X > 1) to build and run tests in a build directory, there is a race condition between the serial_test_low_level target and the test_prep target (a dependency of serial_test_fishscript and serial_test_interactive). As far as I can tell, these events happen in a serial build scenario (“make test” with the “Unix Makefiles” CMake generator): 1. The fish_tests binary is built and executed. 2. The test_prep target (a dependency of serial_test_fishscript) cleans up test directories. 3. Tests in test.fish are executed. In a parallel build scenario, this often happens: 1. Build of the fish_tests binary is started. 2. The test_prep target cleans up test directories. 3. Build of the fish_tests binary is finished. 4. Execution of the fish_tests binary starts. 5. Execution of the fish_tests binary finishes. 6. Tests in test.fish are executed. However, if building the fish_tests binary is fast enough but not instant (e.g. when using ccache), this can happen: 1. Build of the fish_tests binary is started. 2. Build of the fish_tests binary is finished. 3. Execution of the fish_tests binary starts. 4. The test_prep target cleans up test directories. 5. fish_tests tests that depend on said test directories may, depending on timing, fail because they are wiped by test_prep. Fix this by making test_prep a dependency of serial_test_low_level so that test_prep can’t interfere with fish_tests execution. --- cmake/Tests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index 0a4c52d70..fd0c361fc 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -113,6 +113,7 @@ endforeach(TESTTYPE) # Now add a dependency chain between the serial versions. # This ensures they run in order. +add_dependencies(serial_test_low_level test_prep) add_dependencies(serial_test_fishscript serial_test_low_level) add_dependencies(serial_test_interactive serial_test_fishscript)