feat(registry): add the distributed action queue
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 2s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 8s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 11:27:08 +03:00
1 parent 0674b7f9fe
commit 2776e459e3
6 files changed
+181

No files matched your search

+61
View File
@@ -2128,3 +2128,64 @@ VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) {
}
(*svc)->stop_http();
}
// Distributed action queue: enqueue, lease in order, and drop a key once its result lands.
VOID_TEST(RegistryTests, worker_action_queue_enqueue_lease_and_complete) {
Void::FileSystem::TempDir tmp{"vbs_queue_"};
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("q_pub", "q_pass", Role::Publisher).has_value());
auto tok = (*svc)->create_token("q_pub", "q", {"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::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
const std::string key_a = Util::sha256_hex("queue-a");
const std::string key_b = Util::sha256_hex("queue-b");
auto enqueued = send_loopback_http(port, "POST", "/api/v1/queue", auth,
"{\"action_keys\":[\"" + key_a + "\",\"" + key_b + "\"]}");
Void::Testing::expect(enqueued.has_value() && enqueued->status == 200);
if (enqueued) {
Void::Testing::expect(enqueued->body.find("\"queued\":2") != std::string::npos);
}
auto registered = send_loopback_http(port, "POST", "/api/v1/workers", auth, "{}");
Void::Testing::require(registered.has_value() && registered->status == 201);
const std::string worker_id = extract_json_str(registered->body, "worker_id");
auto lease_a = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
"{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}");
Void::Testing::expect(lease_a.has_value() && lease_a->status == 200);
if (lease_a) {
Void::Testing::expect(lease_a->body.find(key_a) != std::string::npos);
}
auto lease_b = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
"{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}");
Void::Testing::expect(lease_b.has_value() && lease_b->status == 200);
if (lease_b) {
Void::Testing::expect(lease_b->body.find(key_b) != std::string::npos);
}
auto empty = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
"{\"worker_id\":\"" + worker_id + "\",\"lease_seconds\":60}");
Void::Testing::expect(empty.has_value() && empty->status == 404);
auto listing = send_loopback_http(port, "GET", "/api/v1/queue", auth);
Void::Testing::expect(listing.has_value() && listing->status == 200);
if (listing) {
Void::Testing::expect(listing->body.find(key_a) != std::string::npos);
}
(*svc)->stop_http();
}