Implement proposed follow-ups on dicussion #35084 (review):
<details>
<summary>Discussion</summary>
In https://github.com/bitcoin/bitcoin/commit/2d3f72fd3fa45ab4e399094c39bfa93bb5a87323 ipc, refactor: Update mp::SpawnProcess call: suggested test coverage:
BOOST_AUTO_TEST_CASE(check_spawned_test) { std::unique_ptripc::Process process{ipc::MakeProcess()}; mp::SocketId socket{mp::SocketError}; char arg0[]{"bitcoin-node"}; char arg1[]{"-ipcfd"}; char arg2[]{"invalid"}; char* argv[]{arg0, arg1, arg2}; auto check_error{[](const std::runtime_error& e) { return std::string_view{e.what()}.starts_with("Invalid -ipcfd number 'invalid'"); }}; BOOST_CHECK_EXCEPTION(process->checkSpawned(3, argv, socket), std::runtime_error, check_error); BOOST_CHECK_EQUAL(socket, mp::SocketError); }
re: #35084 (review)
This is a good test suggestion that would be a nice followup. Note that after https://github.com/bitcoin-core/libmultiprocess/pull/274, the exception will be a little different and look more like "StartSpawned: invalid connect_info" and after https://github.com/bitcoin-core/libmultiprocess/pull/231 the exception on windows will be "CreateFile(pipe) failed" so it could make sense to just check that an exception is thrown and not try to match the text.
Also:
It would be nice to change checkSpawned signature to return optional<SocketId> instead of using bool and an output parameter. (I believe this code is from before C++17 which added std::optional) Could be good to add another test case that doesn't pass an -ipcfd and ensures checkSpawned returns false without throwing an exception. Could be good to add another test case that just passes -ipcfd as the last argument. Could be nice to rename -ipcfd to something more generic like -ipcspawn or -ipcchild since a named pipe path instead of a file descriptor is passed on windows.
</details>
- Add unit test for checkSpawned().
- Make checkSpawned() return std::optionalmp::SocketId.
- Rename -ipcfd to -ipcchild.