0.1 update, make the stop container code more robust and fix some bugs, update the about screen for version 0.1

This commit is contained in:
mrkmntal 2026-08-14 14:28:03 -04:00
commit e8e93d7b21
17 changed files with 449 additions and 43 deletions

View file

@ -34,10 +34,32 @@ void testErrorResponse() {
assert(response.error == "bad");
}
void testCompleteResponseDoesNotNeedPeerClose() {
const std::string raw = "HTTP/1.1 204 No Content\r\nContent-Length: 0\r\n\r\n";
assert(httpResponseComplete(raw));
const auto response = parseHttpResponse(raw);
assert(response.ok());
assert(response.status_code == 204);
}
void testBodylessStatuses() {
for (const int status : {204, 304}) {
const std::string raw = "HTTP/1.1 " + std::to_string(status) + " Status\r\n\r\n";
assert(httpResponseComplete(raw));
const auto parsed = parseHttpResponse(raw);
if (!parsed.ok()) std::cerr << "status=" << status << " error=" << parsed.error << "\n";
assert(parsed.ok());
}
const std::string head = "HTTP/1.1 200 OK\r\n\r\n";
assert(httpResponseComplete(head, "HEAD"));
}
int main() {
testContentLength();
testChunked();
testTruncatedBody();
testErrorResponse();
testCompleteResponseDoesNotNeedPeerClose();
testBodylessStatuses();
std::cout << "HTTP response parser tests passed\n";
}

View file

@ -0,0 +1,19 @@
#include "operation_state.hpp"
#include <cassert>
#include <iostream>
int main() {
OperationState operation;
assert(!operation.busy());
operation.begin("Stopping container", "Please wait...");
assert(operation.busy());
assert(operation.title() == "Stopping container");
assert(operation.message() == "Please wait...");
operation.complete("Container stopped.");
assert(!operation.busy());
assert(operation.result() == "Container stopped.");
std::cout << "Operation state tests passed\n";
}

View file

@ -0,0 +1,22 @@
#include "stop_waiter.hpp"
#include <cassert>
#include <iostream>
int main() {
int stop_requests = 0;
int probes = 0;
const auto first = [&] {
++stop_requests;
return stop_requests == 1 ? StopProbe::Unknown : StopProbe::Stopped;
};
const auto state = waitForStopped([&] {
++probes;
return probes < 2 ? StopProbe::Unknown : StopProbe::Stopped;
}, std::chrono::milliseconds(10), std::chrono::milliseconds(1));
assert(state == StopProbe::Stopped);
assert(first() == StopProbe::Unknown);
assert(first() == StopProbe::Stopped);
assert(stop_requests == 2);
std::cout << "Stop sequence tests passed\n";
}

View file

@ -0,0 +1,33 @@
#include "stop_waiter.hpp"
#include <cassert>
#include <chrono>
#include <iostream>
int main() {
int calls = 0;
const auto stopped = waitForStopped([&] {
return ++calls < 3 ? StopProbe::Running : StopProbe::Stopped;
},
std::chrono::milliseconds(100),
std::chrono::milliseconds(1));
assert(stopped == StopProbe::Stopped);
const auto timed_out = waitForStopped([] { return StopProbe::Unknown; },
std::chrono::milliseconds(5),
std::chrono::milliseconds(1));
assert(timed_out == StopProbe::Unknown);
int transient_calls = 0;
const auto transient = waitForStopped([&] {
++transient_calls;
if (transient_calls < 3) return StopProbe::Unknown;
return StopProbe::Stopped;
}, std::chrono::milliseconds(100), std::chrono::milliseconds(1));
assert(transient == StopProbe::Stopped);
// A failed refresh must not be interpreted as a stopped state.
const auto preserved = waitForStopped([] { return StopProbe::Unknown; },
std::chrono::milliseconds(3),
std::chrono::milliseconds(1));
assert(preserved == StopProbe::Unknown);
std::cout << "Stop waiter tests passed\n";
}