feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security, data, app, realtime, supervisor, clients, CLI, example plus enterprise tenancy, audit, operability, governance, supplychain. Postgres via docker compose for tests.
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
// Route: /stream/download. Chunked framing, range parsing,
|
||||
// passthrough pump with bounded memory and disconnect cleanup.
|
||||
|
||||
#include "test_main.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "realtime/streaming/chunked_body.h"
|
||||
#include "realtime/streaming/passthrough_body.h"
|
||||
|
||||
using namespace molo::realtime;
|
||||
|
||||
int main() {
|
||||
realtime_test::Results r;
|
||||
|
||||
// Chunked framing is byte-exact.
|
||||
{
|
||||
streaming::ChunkedBody body;
|
||||
std::string out = body.write("hello");
|
||||
out += body.flush();
|
||||
out += body.finish();
|
||||
T_CHECK(r, out == "5\r\nhello\r\n0\r\n\r\n");
|
||||
T_CHECK(r, body.finish().empty()); // Idempotent.
|
||||
T_CHECK(r, body.total_bytes() == 5);
|
||||
}
|
||||
|
||||
// Empty writes produce no chunks.
|
||||
{
|
||||
streaming::ChunkedBody body;
|
||||
T_CHECK(r, body.write("").empty());
|
||||
T_CHECK(r, body.finish() == "0\r\n\r\n");
|
||||
}
|
||||
|
||||
// Range parsing: single ranges only.
|
||||
{
|
||||
auto full = streaming::parse_range("bytes=0-99", 100);
|
||||
T_CHECK(r, full.satisfiable && full.first == 0 && full.last == 99);
|
||||
auto tail = streaming::parse_range("bytes=-10", 100);
|
||||
T_CHECK(r, tail.satisfiable && tail.first == 90 && tail.last == 99);
|
||||
auto open = streaming::parse_range("bytes=50-", 100);
|
||||
T_CHECK(r, open.satisfiable && open.first == 50 && open.last == 99);
|
||||
T_CHECK(r, !streaming::parse_range("bytes=0-10,20-30", 100).satisfiable);
|
||||
T_CHECK(r, !streaming::parse_range("bytes=200-", 100).satisfiable);
|
||||
T_CHECK(r, !streaming::parse_range("items=0-1", 100).satisfiable);
|
||||
}
|
||||
|
||||
// Passthrough pumps 8 MiB through a 64 KiB ring with flat memory.
|
||||
{
|
||||
const std::size_t kTotal = 8u * 1024u * 1024u;
|
||||
std::size_t produced = 0;
|
||||
std::size_t consumed = 0;
|
||||
uint64_t checksum = 0;
|
||||
streaming::PassthroughBody pump(64u * 1024u);
|
||||
std::size_t moved = pump.pump(
|
||||
[&](uint8_t* out, std::size_t max) {
|
||||
std::size_t left = kTotal - produced;
|
||||
std::size_t n = left < max ? left : max;
|
||||
for (std::size_t i = 0; i < n; ++i) {
|
||||
out[i] = static_cast<uint8_t>((produced + i) & 0xFFu);
|
||||
}
|
||||
produced += n;
|
||||
return n;
|
||||
},
|
||||
[&](const uint8_t* data, std::size_t len) {
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
checksum += data[i];
|
||||
}
|
||||
consumed += len;
|
||||
return true;
|
||||
});
|
||||
T_CHECK(r, moved == kTotal && consumed == kTotal);
|
||||
T_CHECK(r, !pump.aborted());
|
||||
// Sum of 0..255 repeating over 8 MiB.
|
||||
uint64_t expect = (kTotal / 256) * (255u * 256u / 2);
|
||||
T_CHECK(r, checksum == expect);
|
||||
}
|
||||
|
||||
// Client disconnect aborts the pump promptly.
|
||||
{
|
||||
streaming::PassthroughBody pump(4096);
|
||||
std::size_t calls = 0;
|
||||
std::size_t moved = pump.pump(
|
||||
[&](uint8_t* out, std::size_t max) {
|
||||
(void)out;
|
||||
++calls;
|
||||
return max; // Endless producer.
|
||||
},
|
||||
[&](const uint8_t*, std::size_t) { return false; });
|
||||
T_CHECK(r, pump.aborted());
|
||||
T_CHECK(r, moved == 0 && calls == 1);
|
||||
}
|
||||
|
||||
// Max-bytes cap truncates.
|
||||
{
|
||||
streaming::PassthroughBody pump(4096);
|
||||
std::size_t moved = pump.pump(
|
||||
[&](uint8_t* out, std::size_t max) {
|
||||
(void)out;
|
||||
return max;
|
||||
},
|
||||
[&](const uint8_t*, std::size_t) { return true; }, 100);
|
||||
T_CHECK(r, moved == 100);
|
||||
}
|
||||
|
||||
return r.report("stream/passthrough");
|
||||
}
|
||||
Reference in New Issue
Block a user