mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-22 08:03:40 +00:00
- Match VS Code watermarks (100K/5K) and CharCountAckSize (5K) - ACK ingress bytes (not filtered length) to stay in sync with trackEmitted - Add AckDataBufferer-style batching via terminalFlowAckBuffer - Hibernate listeners ack buffered output so main-process backpressure works
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { FLOW_CHAR_COUNT_ACK_SIZE } from "./terminalFlowConstants.ts";
|
|
import {
|
|
ackTerminalSessionFlow,
|
|
clearTerminalSessionFlowAck,
|
|
createFlowAckBuffer,
|
|
flushTerminalSessionFlowAck,
|
|
} from "./terminalFlowAckBuffer.ts";
|
|
|
|
test("createFlowAckBuffer emits fixed-size batches like VS Code AckDataBufferer", () => {
|
|
const acked: number[] = [];
|
|
const buffer = createFlowAckBuffer((bytes) => acked.push(bytes));
|
|
|
|
buffer.ack(FLOW_CHAR_COUNT_ACK_SIZE);
|
|
assert.deepEqual(acked, []);
|
|
|
|
buffer.ack(1);
|
|
assert.deepEqual(acked, [FLOW_CHAR_COUNT_ACK_SIZE]);
|
|
|
|
buffer.ack(FLOW_CHAR_COUNT_ACK_SIZE);
|
|
assert.deepEqual(acked, [FLOW_CHAR_COUNT_ACK_SIZE, FLOW_CHAR_COUNT_ACK_SIZE]);
|
|
|
|
buffer.ack(FLOW_CHAR_COUNT_ACK_SIZE + 1);
|
|
assert.deepEqual(acked, [
|
|
FLOW_CHAR_COUNT_ACK_SIZE,
|
|
FLOW_CHAR_COUNT_ACK_SIZE,
|
|
FLOW_CHAR_COUNT_ACK_SIZE,
|
|
]);
|
|
});
|
|
|
|
test("flushTerminalSessionFlowAck drains the remainder", () => {
|
|
const acked: number[] = [];
|
|
const buffer = createFlowAckBuffer((bytes) => acked.push(bytes), 100);
|
|
|
|
buffer.ack(250);
|
|
assert.deepEqual(acked, [100, 100]);
|
|
buffer.flush();
|
|
assert.deepEqual(acked, [100, 100, 50]);
|
|
});
|
|
|
|
test("ackTerminalSessionFlow batches per session", () => {
|
|
const acked: Array<{ sessionId: string; bytes: number }> = [];
|
|
const backend = {
|
|
ackSessionFlow: (sessionId: string, bytes: number) => {
|
|
acked.push({ sessionId, bytes });
|
|
},
|
|
};
|
|
|
|
ackTerminalSessionFlow(backend, "sess-a", FLOW_CHAR_COUNT_ACK_SIZE + 1);
|
|
ackTerminalSessionFlow(backend, "sess-b", 10);
|
|
flushTerminalSessionFlowAck("sess-a");
|
|
flushTerminalSessionFlowAck("sess-b");
|
|
|
|
assert.deepEqual(acked, [
|
|
{ sessionId: "sess-a", bytes: FLOW_CHAR_COUNT_ACK_SIZE },
|
|
{ sessionId: "sess-a", bytes: 1 },
|
|
{ sessionId: "sess-b", bytes: 10 },
|
|
]);
|
|
|
|
clearTerminalSessionFlowAck("sess-a");
|
|
clearTerminalSessionFlowAck("sess-b");
|
|
}); |