From 6bbd2b3ee1a45456aaa9710e479cec5d27f69d54 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sat, 14 Feb 2026 12:24:48 +0000 Subject: [PATCH] test(metrics): add v25.2.0 end-to-end assertions for per-IP, history, and HTTP request metrics --- test/test.throughput.ts | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/test.throughput.ts b/test/test.throughput.ts index a6db14d..683c524 100644 --- a/test/test.throughput.ts +++ b/test/test.throughput.ts @@ -168,6 +168,22 @@ tap.test('TCP forward - real-time byte tracking', async (tools) => { const byRoute = m.throughput.byRoute(); console.log('TCP forward — throughput byRoute:', Array.from(byRoute.entries())); + // ── v25.2.0: Per-IP tracking (TCP connections) ── + const byIP = m.connections.byIP(); + console.log('TCP forward — connections byIP:', Array.from(byIP.entries())); + expect(byIP.size).toBeGreaterThan(0); + + const topIPs = m.connections.topIPs(10); + console.log('TCP forward — topIPs:', topIPs); + expect(topIPs.length).toBeGreaterThan(0); + expect(topIPs[0].ip).toBeTruthy(); + + // ── v25.2.0: Throughput history ── + const history = m.throughput.history(10); + console.log('TCP forward — throughput history length:', history.length); + expect(history.length).toBeGreaterThan(0); + expect(history[0].timestamp).toBeGreaterThan(0); + await proxy.stop(); await tools.delayFor(200); }); @@ -233,6 +249,22 @@ tap.test('HTTP forward - byte totals tracking', async (tools) => { expect(bytesIn).toBeGreaterThan(0); expect(bytesOut).toBeGreaterThan(0); + // ── v25.2.0: Per-IP tracking (HTTP connections) ── + const byIP = m.connections.byIP(); + console.log('HTTP forward — connections byIP:', Array.from(byIP.entries())); + expect(byIP.size).toBeGreaterThan(0); + + const topIPs = m.connections.topIPs(10); + console.log('HTTP forward — topIPs:', topIPs); + expect(topIPs.length).toBeGreaterThan(0); + expect(topIPs[0].ip).toBeTruthy(); + + // ── v25.2.0: HTTP request counting ── + const totalReqs = m.requests.total(); + const rps = m.requests.perSecond(); + console.log(`HTTP forward — requests total: ${totalReqs}, perSecond: ${rps}`); + expect(totalReqs).toBeGreaterThan(0); + await proxy.stop(); await tools.delayFor(200); }); @@ -607,6 +639,37 @@ tap.test('Throughput sampling - values appear during active HTTP traffic', async console.log(`Sampling test — recent throughput: in=${tpRecent.in}, out=${tpRecent.out}`); expect(tpRecent.in + tpRecent.out).toBeGreaterThan(0); + // ── v25.2.0: Per-IP tracking ── + const byIP = m.connections.byIP(); + console.log('Sampling test — connections byIP:', Array.from(byIP.entries())); + expect(byIP.size).toBeGreaterThan(0); + + const topIPs = m.connections.topIPs(10); + console.log('Sampling test — topIPs:', topIPs); + expect(topIPs.length).toBeGreaterThan(0); + expect(topIPs[0].ip).toBeTruthy(); + expect(topIPs[0].count).toBeGreaterThanOrEqual(0); + + // ── v25.2.0: Throughput history ── + const history = m.throughput.history(10); + console.log(`Sampling test — throughput history: ${history.length} points`); + if (history.length > 0) { + console.log(' first:', history[0], 'last:', history[history.length - 1]); + } + expect(history.length).toBeGreaterThan(0); + expect(history[0].timestamp).toBeGreaterThan(0); + + // ── v25.2.0: Per-IP throughput ── + const tpByIP = m.throughput.byIP(); + console.log('Sampling test — throughput byIP:', Array.from(tpByIP.entries())); + + // ── v25.2.0: HTTP request counting ── + const totalReqs = m.requests.total(); + const rps = m.requests.perSecond(); + const rpm = m.requests.perMinute(); + console.log(`Sampling test — HTTP requests: total=${totalReqs}, perSecond=${rps}, perMinute=${rpm}`); + expect(totalReqs).toBeGreaterThan(0); + // Stop sending sending = false; await sendLoop;