metrics: peak gauges for in-flight queries, stream connections and the query log queue
This commit is contained in:
@@ -329,6 +329,52 @@ test "a canceled serve does not wait for a live connection" {
|
||||
try client_result;
|
||||
}
|
||||
|
||||
test "the connections peak is the most slots held at once" {
|
||||
if (!build_options.integration) return error.SkipZigTest;
|
||||
|
||||
const gpa = testing.allocator;
|
||||
var threaded: std.Io.Threaded = .init(gpa, .{});
|
||||
defer threaded.deinit();
|
||||
const io = threaded.io();
|
||||
|
||||
var fake: FakeUpstream = .{ .reply = response_bytes };
|
||||
var h_owner: upstream_owner.Borrowed = .{};
|
||||
var h = bareHandler(h_owner.client(fake.client()));
|
||||
|
||||
const listen_address: net.IpAddress = try .parse("127.0.0.1", 0);
|
||||
var server = try tcp_server.TcpServer.listen(gpa, io, listen_address, &h, .{
|
||||
.max_connections = 3,
|
||||
.idle_timeout = .{ .raw = .fromSeconds(600), .clock = .awake },
|
||||
});
|
||||
const server_address = server.boundAddress();
|
||||
|
||||
var serving: std.Io.Group = .init;
|
||||
try serving.concurrent(io, tcp_server.TcpServer.serve, .{ &server, io });
|
||||
|
||||
var answered: [2]std.Io.Event = @splat(.unset);
|
||||
var client_results: [2]anyerror!void = @splat({});
|
||||
var clients_group: std.Io.Group = .init;
|
||||
for (&answered, &client_results) |*event, *result| {
|
||||
try clients_group.concurrent(io, holdConnection, .{ io, server_address, event, result });
|
||||
}
|
||||
for (&answered) |*event| event.waitUncancelable(io);
|
||||
|
||||
// Both replies prove both slots are claimed, and the listener has room for
|
||||
// a third that never arrives.
|
||||
const held_open = server.connectionsPeak();
|
||||
|
||||
server.deinit(io);
|
||||
serving.await(io) catch |err| switch (err) {
|
||||
error.Canceled => unreachable,
|
||||
};
|
||||
clients_group.await(io) catch |err| switch (err) {
|
||||
error.Canceled => unreachable,
|
||||
};
|
||||
|
||||
for (client_results) |result| try result;
|
||||
try testing.expectEqual(@as(u64, 2), held_open);
|
||||
}
|
||||
|
||||
/// The first slot the server would hand out, read after `serve` has returned so
|
||||
/// nothing can be writing it.
|
||||
fn firstFreeSlot(server: *const tcp_server.TcpServer) ?usize {
|
||||
|
||||
Reference in New Issue
Block a user