test(#838): reject retry masking and dropped replies

This commit is contained in:
ms-lead-reviewer
2026-07-18 01:38:22 -05:00
parent 6b2e4adf62
commit b3728fdeaa
3 changed files with 102 additions and 20 deletions

View File

@@ -53,29 +53,39 @@ afterEach(async () => {
});
describe('newline-framed broker test client', () => {
test('retries an empty early close and parses the complete newline-terminated retry', async () => {
const broker = await scriptedBroker([[], [Buffer.from('{"ok":true'), Buffer.from('}\n')]]);
test('rejects an empty early close without retrying into a false green', async () => {
const broker = await scriptedBroker([[], [Buffer.from('{"ok":true}\n')]]);
await expect(requestBrokerReply(broker.socketPath, { action: 'probe' })).resolves.toEqual({
ok: true,
});
expect(broker.connections()).toBe(2);
});
test('rejects repeated truncated early closes with response bytes and length', async () => {
const truncated = Buffer.from('{"ok":');
const broker = await scriptedBroker([[truncated], [truncated]]);
const failure = await requestBrokerReply(
broker.socketPath,
{ action: 'probe' },
{ earlyCloseRetries: 1 },
).catch((error: unknown) => error);
const failure = await requestBrokerReply(broker.socketPath, { action: 'probe' }).catch(
(error: unknown) => error,
);
expect(failure).toBeInstanceOf(BrokerTransportError);
expect(failure).toMatchObject({
kind: 'early-close',
attempts: 2,
attempts: 1,
responseLength: 0,
responseHex: '',
});
expect(failure).toHaveProperty(
'message',
expect.stringMatching(/closed before newline.*length=0.*hex=<empty>/i),
);
expect(broker.connections()).toBe(1);
});
test('rejects repeated truncated early closes with response bytes and length', async () => {
const truncated = Buffer.from('{"ok":');
const broker = await scriptedBroker([[truncated], [Buffer.from('{"ok":true}\n')]]);
const failure = await requestBrokerReply(broker.socketPath, { action: 'probe' }).catch(
(error: unknown) => error,
);
expect(failure).toBeInstanceOf(BrokerTransportError);
expect(failure).toMatchObject({
kind: 'early-close',
attempts: 1,
responseLength: 6,
responseHex: '7b226f6b223a',
});
@@ -83,7 +93,7 @@ describe('newline-framed broker test client', () => {
'message',
expect.stringMatching(/closed before newline.*length=6.*bytes=.*ok/i),
);
expect(broker.connections()).toBe(2);
expect(broker.connections()).toBe(1);
});
test('rejects a newline-terminated malformed broker reply without retrying', async () => {