feat(worker): drain the queue with parallel workers
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 9s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 7s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 16s
VoidBuildSystem CI / fuzz-clang (push) Failing after 6s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 1m8s

This commit is contained in:
faumaray committed 2026-12-05 13:17:25 +03:00
1 parent af2be817a5
commit ac08887d8f
6 files changed
+176 -30

No files matched your search

+98
View File
@@ -2441,3 +2441,101 @@ VOID_TEST(RegistryTests, worker_executes_remote_action_spec) {
}
(*svc)->stop_http();
}
// `vbs worker --queue --parallel N`: several lease/execute loops drain the queue concurrently;
// every action runs exactly once.
VOID_TEST(RegistryTests, worker_parallel_drains_queue_without_duplicates) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_parallel_"};
RegistryConfig cfg;
cfg.data_dir = tmp / "reg_data";
cfg.bind_address = "127.0.0.1";
cfg.port = 0;
cfg.bootstrap_admin_user = "admin";
cfg.bootstrap_admin_password = "admin_pw";
auto svc = RegistryService::open(cfg);
Void::Testing::expect(svc.has_value());
if (!svc) {
return;
}
Void::Testing::expect((*svc)->create_user("par_pub", "par_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("par_pub", "par", {"read", "publish"});
Void::Testing::expect(tok.has_value());
if (!tok) {
return;
}
Void::Testing::expect((*svc)->start_http().has_value());
const auto port = (*svc)->bound_port();
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
const std::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
const auto workdir = tmp / "workdir";
std::filesystem::create_directories(workdir);
std::vector<std::string> keys;
for (const char *name : {"alpha", "beta"}) {
const std::string key = Util::sha256_hex(std::string{"parallel-"} + name);
keys.push_back(key);
const std::string spec = "{\"schema_version\":1,\"action_key\":\"" + key +
"\",\"command\":[\"/bin/sh\",\"-c\",\"echo start-" + name +
" >> order.log; sleep 0.4; echo end-" + name +
" >> order.log\"],\"working_directory\":\"" + workdir.string() +
"\",\"output_paths\":[]}";
auto put = send_loopback_http(port, "PUT", "/api/v1/cas/actions/" + key, auth, spec);
Void::Testing::expect(put.has_value() && put->status == 201);
}
auto enqueued =
send_loopback_http(port, "POST", "/api/v1/queue", auth,
"{\"action_keys\":[\"" + keys[0] + "\",\"" + keys[1] + "\"]}");
Void::Testing::expect(enqueued.has_value() && enqueued->status == 200);
Platform::ProcessRequest worker;
worker.executable = vbs_bin;
worker.arguments = {"worker", "--registry", reg_url, "--queue",
"--parallel", "2", "--build-dir", (tmp / "build").string()};
worker.environment.set_vars["VBS_REGISTRY_TOKEN"] = *tok;
worker.timeout = std::chrono::seconds{120};
auto worker_res = Platform::run_supervised(worker);
Void::Testing::expect_eq(
worker_res ? (worker_res->succeeded() ? std::string{}
: (worker_res->stdout_data + worker_res->stderr_data))
: worker_res.error().message(),
std::string{});
auto order_text = Void::FileSystem::read_file(workdir / "order.log");
Void::Testing::require(order_text.has_value());
std::set<std::string> running;
std::set<std::string> started;
std::set<std::string> ended;
bool overlap = false;
for (std::size_t pos = 0; pos < order_text->size();) {
const auto eol = order_text->find('\n', pos);
const std::string line = order_text->substr(pos, eol - pos);
pos = eol == std::string::npos ? order_text->size() : eol + 1;
if (line.starts_with("start-")) {
const std::string name = line.substr(6);
Void::Testing::expect(started.insert(name).second); // never leased twice
if (!running.empty()) {
overlap = true;
}
running.insert(name);
} else if (line.starts_with("end-")) {
const std::string name = line.substr(4);
ended.insert(name);
running.erase(name);
}
}
Void::Testing::expect_eq(started.size(), std::size_t{2});
Void::Testing::expect_eq(ended.size(), std::size_t{2});
Void::Testing::expect(overlap); // the two actions ran concurrently
auto queue_state = send_loopback_http(port, "GET", "/api/v1/queue", auth);
Void::Testing::expect(queue_state.has_value() && queue_state->status == 200);
if (queue_state) {
Void::Testing::expect(queue_state->body.find("\"pending\":[]") != std::string::npos);
}
(*svc)->stop_http();
}