From 8d3257fe558727a3d64902e27539b5a5c28ba49f Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Wed, 18 Feb 2026 22:14:54 +0100 Subject: Stop stalled backups --- test/http.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'test/http.c') diff --git a/test/http.c b/test/http.c index 8309d5e..27385ab 100644 --- a/test/http.c +++ b/test/http.c @@ -271,5 +271,76 @@ int main(int argc, char **argv) { assert(code == 401); // Unauthorized } + // Test: Starting a new backup should interrupt the previous RUNNING backup + { + // Begin first backup + curlRes = curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/api/report"); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_setopt(curl, CURLOPT_POST, 1L); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_from_memory); + assert(curlRes == CURLE_OK); + + char req_buf[256]; + snprintf(req_buf, sizeof(req_buf), + "{\"client\": \"client1\", \"secret\": \"%s\", \"event\": \"begin_backup\"}", + client_secret); + struct memory req_body = { .body = req_buf, .size = strlen(req_buf) }; + curlRes = curl_easy_setopt(curl, CURLOPT_READDATA, &req_body); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_memory); + assert(curlRes == CURLE_OK); + struct memory body = {0}; + curlRes = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_perform(curl); + assert(curlRes == CURLE_OK); + long code; + curlRes = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); + assert(code == 204); + body = (struct memory){0}; + + progress_time(TIME_JOIN(0, 10, 0)); // Advance 10 minutes + + // Begin second backup (should interrupt the first) + snprintf(req_buf, sizeof(req_buf), + "{\"client\": \"client1\", \"secret\": \"%s\", \"event\": \"begin_backup\"}", + client_secret); + req_body = (struct memory){ .body = req_buf, .size = strlen(req_buf) }; + curlRes = curl_easy_setopt(curl, CURLOPT_READDATA, &req_body); + assert(curlRes == CURLE_OK); + body = (struct memory){0}; + curlRes = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_perform(curl); + assert(curlRes == CURLE_OK); + curlRes = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); + assert(code == 204); + body = (struct memory){0}; + + // Use internal function to verify backup statuses + struct Request req = { .server = &server }; + struct GetClientResult *result = malloc(sizeof(struct GetClientResult) + sizeof(struct BackupRecord) * MAX_BACKUPS_DISPLAY); + int ret = get_client_with_backups(&req, 1, result); + assert(ret == 0); + assert(result->found == 1); + + // Should have at least 2 backups (the interrupted one and the running one) + // Note: There may be more from earlier tests + assert(result->backups_len >= 2); + + // Backups are ordered by started DESC, so newest first + // The most recent backup should be RUNNING + assert(strcmp(result->backups[0].status, "RUNNING") == 0); + // The previous backup should be INTERRUPTED + assert(strcmp(result->backups[1].status, "INTERRUPTED") == 0); + // The interrupted backup should have a completed timestamp + assert(result->backups[1].completed[0] != '\0'); + + free(result); + } + web_join(&server); } -- cgit v1.2.3