feat(system,config,sqlite): implement VL-001, VL-003, VL-010, VL-011
This commit is contained in:
1 parent
adfc8548dc
commit
b50131f52e
14 files changed
+2660
-139
No files matched your search
@@ -19,6 +19,7 @@
|
||||
#include <fstream>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
@@ -294,3 +295,72 @@ Void::Testing::Test system_replace_file_temp_ownership_and_metrics()
|
||||
expect(sample.valid);
|
||||
expect(sample.ratio >= 0.0);
|
||||
}
|
||||
|
||||
Void::Testing::Test system_terminate_reaps_entire_process_group_after_leader_exits()
|
||||
{
|
||||
Void::FileSystem::TempDir tmp{"void_sys_pgid_"};
|
||||
const auto marker = tmp / "grandchild_ticks.txt";
|
||||
|
||||
Void::Process::SpawnOptions opts;
|
||||
opts.executable = VOID_PROCESS_HELPER_PATH;
|
||||
opts.arguments = {"grandchild-ignore-sigterm", marker.string()};
|
||||
opts.new_process_group = true;
|
||||
opts.stdin_pipe = false;
|
||||
opts.stderr_pipe = false;
|
||||
auto spawned = Void::Process::spawn(opts);
|
||||
require(spawned.has_value());
|
||||
|
||||
// Wait for grandchild readiness signal on stdout.
|
||||
std::string ready_buf;
|
||||
std::array<char, 64> chunk{};
|
||||
const auto wait_start = std::chrono::steady_clock::now();
|
||||
while (ready_buf.find("ready\n") == std::string::npos) {
|
||||
const ssize_t n = ::read(spawned->stdout_fd(), chunk.data(), chunk.size());
|
||||
if (n > 0) {
|
||||
ready_buf.append(chunk.data(), static_cast<std::size_t>(n));
|
||||
continue;
|
||||
}
|
||||
if (n < 0 && errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
if (std::chrono::steady_clock::now() - wait_start > std::chrono::seconds{5}) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
}
|
||||
require(ready_buf.find("ready\n") != std::string::npos);
|
||||
|
||||
// Wait until direct leader has exited and been reaped, while the
|
||||
// SIGTERM-ignoring grandchild continues running in the process group.
|
||||
std::optional<Void::Process::ExitStatus> leader_status;
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
auto w = spawned->try_wait();
|
||||
require(w.has_value());
|
||||
if (w->has_value()) {
|
||||
leader_status = *w;
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{5});
|
||||
}
|
||||
require(leader_status.has_value());
|
||||
expect(leader_status->exited);
|
||||
expect_eq(leader_status->code, 0);
|
||||
expect(spawned->process_group_alive());
|
||||
|
||||
// terminate(60ms) must send SIGTERM to -pgid, wait out grace since the
|
||||
// grandchild ignores SIGTERM, escalate to SIGKILL, and not return until
|
||||
// ESRCH confirms all process-group members are gone.
|
||||
auto term = spawned->terminate(std::chrono::milliseconds{60});
|
||||
require(term.has_value());
|
||||
expect(!spawned->process_group_alive());
|
||||
|
||||
std::error_code ec;
|
||||
const auto size_after_terminate = std::filesystem::file_size(marker, ec);
|
||||
require(!ec);
|
||||
expect(size_after_terminate > 0U);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
||||
const auto size_later = std::filesystem::file_size(marker, ec);
|
||||
require(!ec);
|
||||
expect_eq(size_later, size_after_terminate);
|
||||
}
|
||||
Reference in new issue
Block a user