diff options
| author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 00:54:26 +0200 |
|---|---|---|
| committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-08 01:33:00 +0200 |
| commit | 52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4 (patch) | |
| tree | c823138a799d80763ee801c77f6185695f754839 /src/server.c | |
| parent | clang-format: don't break string literals (diff) | |
| download | cimple-52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4.tar.gz cimple-52fd7a89473c4b7e18862a5c1f9a2b6715cc41c4.zip | |
test: verify that added runs are in the database
And that they're marked as finished. It immediately exposed some
concurrency bugs, so some locking has been fixed.
Diffstat (limited to 'src/server.c')
| -rw-r--r-- | src/server.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/server.c b/src/server.c index da9cfc3..a4358d5 100644 --- a/src/server.c +++ b/src/server.c @@ -125,24 +125,21 @@ static int server_enqueue_run(struct server *server, struct run *run) { int ret = 0; - ret = server_lock(server); + ret = storage_run_create(&server->storage, run_get_url(run), run_get_rev(run)); if (ret < 0) return ret; + run_set_id(run, ret); - ret = storage_run_create(&server->storage, run_get_url(run), run_get_rev(run)); + ret = server_lock(server); if (ret < 0) - goto unlock; - run_set_id(run, ret); + return ret; run_queue_add_last(&server->run_queue, run); log("Added a new run %d for repository %s to the queue\n", run_get_id(run), run_get_url(run)); server_notify(server); - -unlock: server_unlock(server); - return ret; } @@ -297,9 +294,7 @@ static int server_handle_cmd_finished(const struct msg *request, UNUSED struct m struct server *server = (struct server *)ctx->arg; int ret = 0; - log("Received a \"run finished\" message from worker %d\n", ctx->fd); - - int run_id; + int run_id = 0; struct proc_output output; ret = msg_finished_parse(request, &run_id, &output); @@ -307,12 +302,16 @@ static int server_handle_cmd_finished(const struct msg *request, UNUSED struct m return ret; ret = storage_run_finished(&server->storage, run_id, output.ec); - proc_output_free(&output); if (ret < 0) { log_err("Failed to mark run %d as finished\n", run_id); - return ret; + goto free_output; } + log("Marked run %d as finished\n", run_id); + +free_output: + proc_output_free(&output); + return ret; } |
