Give the link's liveness one owner
Test / lint (pull_request) Successful in 24s
Test / test (18) (pull_request) Successful in 32s
Test / test (20) (pull_request) Successful in 32s
Test / test (22) (pull_request) Successful in 32s
Test / test (24) (pull_request) Successful in 32s
Mirror / push (push) Has been cancelled
Test / test (26) (pull_request) Successful in 32s
Test / lint (pull_request) Successful in 24s
Test / test (18) (pull_request) Successful in 32s
Test / test (20) (pull_request) Successful in 32s
Test / test (22) (pull_request) Successful in 32s
Test / test (24) (pull_request) Successful in 32s
Mirror / push (push) Has been cancelled
Test / test (26) (pull_request) Successful in 32s
This commit is contained in:
+56
-23
@@ -19,7 +19,7 @@ import { HeldMessages } from '../src/held-messages.ts';
|
||||
import { IncomingRequests, refusedSegmentStatus } from '../src/incoming-requests.ts';
|
||||
import { UnansweredError } from '../src/unanswered-error.ts';
|
||||
import { createSms } from '../src/sms.ts';
|
||||
import { LinkGate } from '../src/link-gate.ts';
|
||||
import { LinkLife } from '../src/link-life.ts';
|
||||
import { SendWindow } from '../src/send-window.ts';
|
||||
import { Reassembler, decodeSegments } from '../src/reassembly.ts';
|
||||
import { Session } from '../src/session.ts';
|
||||
@@ -104,6 +104,7 @@ function abortAfter(
|
||||
function incomingOn(session: Session, options: Partial<IncomingRequestsOptions> = {}): IncomingRequests {
|
||||
return new IncomingRequests({
|
||||
dlrMerger: new DlrMerger({ log: silentLog, max: 10, timeout: 10_000 }),
|
||||
link: new LinkLife({ log: silentLog, reconnects: false, timeout: 100 }),
|
||||
log: silentLog,
|
||||
sendPastDrain: () => Promise.resolve({ err: new Error('never sent') }),
|
||||
session,
|
||||
@@ -748,14 +749,15 @@ describe('reconnect', () => {
|
||||
|
||||
closeAfter(t, session);
|
||||
|
||||
const incoming = incomingOn(session, { onRequest: async () => { await delay(10); return false; } });
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 100 });
|
||||
const incoming = incomingOn(session, { link, onRequest: async () => { await delay(10); return false; } });
|
||||
let messages = 0;
|
||||
|
||||
session.on('sms', () => { messages++; });
|
||||
|
||||
const handled = incoming.handle(submitPdu(1));
|
||||
|
||||
incoming.clear();
|
||||
link.drop();
|
||||
|
||||
await handled;
|
||||
|
||||
@@ -1401,13 +1403,13 @@ describe('sends across a reconnect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('LinkGate', () => {
|
||||
describe('LinkLife', () => {
|
||||
test('refuses a hold whose deadline has already passed', async () => {
|
||||
let now = 0;
|
||||
const gate = new LinkGate({ log: silentLog, now: () => now, timeout: 100 });
|
||||
const waitForLink = gate.hold(undefined);
|
||||
const link = new LinkLife({ log: silentLog, now: () => now, reconnects: true, timeout: 100 });
|
||||
const waitForLink = link.hold(undefined);
|
||||
|
||||
gate.shut(true);
|
||||
link.drop();
|
||||
now = 101;
|
||||
|
||||
const held = await waitForLink();
|
||||
@@ -1416,42 +1418,73 @@ describe('LinkGate', () => {
|
||||
});
|
||||
|
||||
test('holds on a timer that keeps the process alive', async () => {
|
||||
const gate = new LinkGate({ log: silentLog, timeout: 10_000 });
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 10_000 });
|
||||
const timers = (): number => process.getActiveResourcesInfo().filter(name => name === 'Timeout').length;
|
||||
|
||||
gate.shut(true);
|
||||
link.drop();
|
||||
|
||||
const before = timers();
|
||||
const held = gate.hold(undefined)();
|
||||
const held = link.hold(undefined)();
|
||||
|
||||
assert.equal(timers(), before + 1, 'an unref\'d timer is not counted here, which is the point');
|
||||
|
||||
gate.open();
|
||||
link.open();
|
||||
|
||||
assert.deepEqual(await held, {});
|
||||
});
|
||||
|
||||
// addEventListener never fires for a signal that already aborted, so it would wait out the timeout.
|
||||
test('gives up at once on a signal that was already aborted', async () => {
|
||||
const gate = new LinkGate({ log: silentLog, timeout: 100 });
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 100 });
|
||||
|
||||
gate.shut(true);
|
||||
link.drop();
|
||||
|
||||
const held = await gate.hold(AbortSignal.abort())();
|
||||
const held = await link.hold(AbortSignal.abort())();
|
||||
|
||||
assert.match(held.err?.message ?? '', /Aborted while waiting for a link/);
|
||||
});
|
||||
|
||||
test('awaits the next link only while shut with one on its way', () => {
|
||||
const gate = new LinkGate({ log: silentLog, timeout: 100 });
|
||||
test('awaits the next link only while down with one on its way', () => {
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 100 });
|
||||
|
||||
assert.equal(gate.awaitsNextLink(), false, 'up');
|
||||
gate.shut(true);
|
||||
assert.equal(gate.awaitsNextLink(), true, 'shut, returning');
|
||||
gate.open();
|
||||
assert.equal(gate.awaitsNextLink(), false, 'reopened');
|
||||
gate.shut(false);
|
||||
assert.equal(gate.awaitsNextLink(), false, 'shut for good');
|
||||
assert.equal(link.awaitsNextLink(), false, 'up');
|
||||
link.drop();
|
||||
assert.equal(link.awaitsNextLink(), true, 'down, returning');
|
||||
link.attach();
|
||||
assert.equal(link.awaitsNextLink(), true, 'attached, not yet bound');
|
||||
link.open();
|
||||
assert.equal(link.awaitsNextLink(), false, 'reopened');
|
||||
link.drop();
|
||||
link.stop();
|
||||
assert.equal(link.awaitsNextLink(), false, 'down, stopped');
|
||||
assert.match(link.refusal()?.message ?? '', /closed/, 'stopped while down');
|
||||
link.end();
|
||||
assert.equal(link.awaitsNextLink(), false, 'ended');
|
||||
assert.equal(new LinkLife({ log: silentLog, reconnects: false, timeout: 100 }).drop(), true);
|
||||
});
|
||||
|
||||
test('drops an attached link once, and counts each drop', () => {
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 100 });
|
||||
const generation = link.generation();
|
||||
|
||||
assert.equal(link.drop(), true);
|
||||
assert.equal(link.drop(), false, 'already down');
|
||||
assert.equal(link.generation(), generation + 1);
|
||||
link.attach();
|
||||
assert.equal(link.drop(), true, 'a new link drops again');
|
||||
assert.equal(link.generation(), generation + 2);
|
||||
});
|
||||
|
||||
test('releases a held request with the reason once the link ends', async () => {
|
||||
const link = new LinkLife({ log: silentLog, reconnects: true, timeout: 0 });
|
||||
|
||||
link.drop();
|
||||
|
||||
const held = link.hold(undefined)();
|
||||
|
||||
link.end();
|
||||
|
||||
assert.match((await held).err?.message ?? '', /Session is closed/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user