fix: report combined local transport failures once
This commit is contained in:
@@ -271,3 +271,53 @@ for (const failure of ['record', 'close']) {
|
||||
assert.throws(() => h.transport.send('late'), /open/i);
|
||||
});
|
||||
}
|
||||
|
||||
test('non-text and cleanup failures reach a single terminal observer together', async () => {
|
||||
const observed: unknown[] = [];
|
||||
const h = await setup({ onFault: (error) => { if (observed.length === 0) observed.push(error); } });
|
||||
h.transport.connect(h.url);
|
||||
const socket = h.sockets[0]!;
|
||||
const cleanupError = new Error('close failed');
|
||||
socket.closeError = cleanupError;
|
||||
socket.message(new ArrayBuffer(1));
|
||||
assert.equal(h.faults.length, 1);
|
||||
assert.equal(observed[0], h.faults[0]);
|
||||
const fault = observed[0] as Error & { errors: unknown[] };
|
||||
assert.ok(fault instanceof Error);
|
||||
assert.equal(fault.errors.length, 2);
|
||||
assert.ok(fault.errors[0] instanceof TypeError);
|
||||
assert.equal(fault.errors[1], cleanupError);
|
||||
assert.throws(() => h.transport.send('late'), /open/i);
|
||||
});
|
||||
|
||||
for (const operation of ['receive-record', 'error-record', 'send-record', 'send']) {
|
||||
test(`${operation} and close failures are reported once and thrown as the same combined fault`, async () => {
|
||||
const primary = new Error('primary failed');
|
||||
const cleanup = new Error('close failed');
|
||||
const observed: unknown[] = [];
|
||||
const h = await setup({
|
||||
...(operation === 'send' ? {} : { record: () => { throw primary; } }),
|
||||
onFault: (error) => { if (observed.length === 0) observed.push(error); },
|
||||
});
|
||||
h.transport.connect(h.url);
|
||||
const socket = h.sockets[0]!;
|
||||
socket.open();
|
||||
socket.closeError = cleanup;
|
||||
if (operation === 'send') socket.sendError = primary;
|
||||
let thrown: unknown;
|
||||
try {
|
||||
if (operation === 'receive-record') socket.message('frame');
|
||||
else if (operation === 'error-record') socket.onerror?.({} as Event);
|
||||
else h.transport.send('frame');
|
||||
} catch (error) { thrown = error; }
|
||||
assert.equal(h.faults.length, 1);
|
||||
assert.equal(thrown, observed[0]);
|
||||
assert.equal(thrown, h.faults[0]);
|
||||
assert.ok(thrown instanceof Error);
|
||||
const errors = (thrown as Error & { errors: unknown[] }).errors;
|
||||
assert.equal(errors.length, 2);
|
||||
assert.equal(errors[0], primary);
|
||||
assert.equal(errors[1], cleanup);
|
||||
assert.throws(() => h.transport.send('late'), /open/i);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user