feat(worker): renew leases and watch an idle queue
VoidBuildSystem CI / sanitizers-gcc16 (push) Failing after 5s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 2s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 13s
VoidBuildSystem CI / wine-windows-gcc16 (push) Failing after 49s

This commit is contained in:
faumaray committed 2026-12-05 12:03:46 +03:00
1 parent 8dac19c3ea
commit 55bc0529b9
8 files changed
+152 -17

No files matched your search

+34
View File
@@ -2170,6 +2170,40 @@ VOID_TEST(RegistryTests, worker_cli_leases_publishes_and_reports_result) {
Void::Testing::expect(loop_res->stdout_data.find("queue empty") != std::string::npos);
Void::Testing::expect(loop_res->stdout_data.find(action_key) != std::string::npos);
}
// Idle timeout: an empty queue keeps the worker alive for the configured time.
Platform::ProcessRequest idle_worker = loop_worker;
idle_worker.arguments.push_back("--idle-timeout");
idle_worker.arguments.push_back("1");
const auto idle_start = std::chrono::steady_clock::now();
auto idle_res = Platform::run_supervised(idle_worker);
const auto idle_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - idle_start);
Void::Testing::expect(idle_res.has_value() && idle_res->succeeded());
Void::Testing::expect(idle_elapsed >= std::chrono::milliseconds{900});
// Lease renewal extends a live lease and rejects a wrong token.
auto enqueued_once_more = send_loopback_http(port, "POST", "/api/v1/queue", auth,
"{\"action_keys\":[\"" + action_key + "\"]}");
Void::Testing::expect(enqueued_once_more.has_value() && enqueued_once_more->status == 200);
auto renew_worker = send_loopback_http(port, "POST", "/api/v1/workers", auth, "{}");
Void::Testing::require(renew_worker.has_value() && renew_worker->status == 201);
const std::string renew_worker_id = extract_json_str(renew_worker->body, "worker_id");
auto lease_for_renew =
send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
"{\"worker_id\":\"" + renew_worker_id + "\",\"lease_seconds\":1}");
Void::Testing::require(lease_for_renew.has_value() && lease_for_renew->status == 200);
const std::string renew_token = extract_json_str(lease_for_renew->body, "lease_token");
auto wrong_renew = send_loopback_http(port, "POST", "/api/v1/actions/" + action_key + "/renew",
auth, "{\"lease_token\":\"deadbeef\"}");
Void::Testing::expect(wrong_renew.has_value() && wrong_renew->status == 403);
auto renewed =
send_loopback_http(port, "POST", "/api/v1/actions/" + action_key + "/renew", auth,
"{\"lease_token\":\"" + renew_token + "\",\"lease_seconds\":120}");
Void::Testing::expect(renewed.has_value() && renewed->status == 200);
if (renewed) {
Void::Testing::expect(renewed->body.find("expires_epoch") != std::string::npos);
}
(*svc)->stop_http();
}