CTest FIXTURES_SETUP start Server in background

Hi,

my goal is to start my server before running the tests. I therefore use the FIXTURES_SETUP functionality. My understanding is that a tests needs to finish and return a value, which tells cmake if the test is finished.
Therefore the server needs to be spawned as an independent child process. I wrote a C++ Script with boost Process:

bp::child serverProcess("@SERVER_EXECUTABLE@", (bp::std_out & bp::std_err) > "test1.log", bp::std_in < bp::null);
// bp::child serverProcess("@SERVER_EXECUTABLE@", (bp::std_out & bp::std_err) > bp::null, bp::std_in < bp::null);

std::this_thread::sleep_for(std::chrono::seconds(2));

if(!serverProcess.running()) {
   std::cout << "Server not running\n";
   return -1;
}

std::ofstream file { "@PROCESS_ID_FILE@" };
file << serverProcess.id();

serverProcess.detach();
std::cout << "Detached Server\n";

Rather simple script. Start a process, wait a few seconds, check if server still runs, detach process.

On Linux I had to redirect the stream to null or a file or something like that as otherwise the process is attached to the current terminal or something like that?

On Windows I needed to modify the Boost.Process Code according to Closing parent console kills detached process in Windows · Issue #186 · boostorg/process · GitHub. Otherwise nothing worked at all.

With this the code itself seems to work fine. Start executable, server started, terminal closed, server still running.

But CTest won’t finish the test. The last line is executed and still ctest won’t stop. Although I’m not completely sure how reliable the behavior is currently.

What could be the cause? Is ctest checking for anything specific?

For reference the cmake code:

add_test(NAME setupServer COMMAND StartServer)
add_test(NAME shutdownServer COMMAND StopServer)

add_executable(ServerE2ETests)
....
catch_discover_tests(ServerE2ETests
    PROPERTIES
        FIXTURES_REQUIRED Server
        LABELS "End2EndTests"
)

set_tests_properties(setupServer PROPERTIES FIXTURES_SETUP Server)
set_tests_properties(shutdownServer PROPERTIES FIXTURES_CLEANUP Server)
set_tests_properties(setupServer shutdownServer PROPERTIES LABELS "End2EndTests")

Most likely unrelated, but I also noticed that “StartServer” is labeled as Test 2, StopServer as Test 3 and E2E Test as Test 1. Why is this not numbered in the way it’s executed?