Hold the bounds tests through offer()
This commit is contained in:
+16
-11
@@ -5,6 +5,7 @@ import type { Collected, LostGroup } from '../src/reassembly.ts';
|
|||||||
import type { Dlr } from '../src/dlr.ts';
|
import type { Dlr } from '../src/dlr.ts';
|
||||||
import type { ErrorName } from '../src/defs/errors.ts';
|
import type { ErrorName } from '../src/defs/errors.ts';
|
||||||
import type { IncomingDeps } from '../src/incoming-requests.ts';
|
import type { IncomingDeps } from '../src/incoming-requests.ts';
|
||||||
|
import type { MessageHold } from '../src/held-messages.ts';
|
||||||
import type { MessageState } from '../src/defs/constants.ts';
|
import type { MessageState } from '../src/defs/constants.ts';
|
||||||
import type { MessageDlr } from '../src/session.ts';
|
import type { MessageDlr } from '../src/session.ts';
|
||||||
import type { PduObject, PduObjectInput } from '../src/pdu.ts';
|
import type { PduObject, PduObjectInput } from '../src/pdu.ts';
|
||||||
@@ -1518,12 +1519,16 @@ describe('held message bounds', () => {
|
|||||||
return [submitPdu(seqNr)];
|
return [submitPdu(seqNr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function offer(held: HeldMessages, seqNr: number): MessageHold {
|
||||||
|
return held.offer(message(seqNr), 1, () => ({}), () => true);
|
||||||
|
}
|
||||||
|
|
||||||
test('is full at its count, and a re-used sequence number replaces rather than adding', () => {
|
test('is full at its count, and a re-used sequence number replaces rather than adding', () => {
|
||||||
const held = new HeldMessages({ log: silentLog, max: 2, maxOctets: 1_000_000, timeout: 10_000 });
|
const held = new HeldMessages({ log: silentLog, max: 2, maxOctets: 1_000_000, timeout: 10_000 });
|
||||||
const first = held.hold(message(1), 1);
|
const first = offer(held, 1);
|
||||||
|
|
||||||
held.hold(message(2), 1);
|
offer(held, 2);
|
||||||
held.hold(message(2), 1);
|
offer(held, 2);
|
||||||
|
|
||||||
assert.equal(held.size, 2);
|
assert.equal(held.size, 2);
|
||||||
assert.equal(held.octetsHeld, 2 * 1026, 'the replaced message leaves its octets with it');
|
assert.equal(held.octetsHeld, 2 * 1026, 'the replaced message leaves its octets with it');
|
||||||
@@ -1537,22 +1542,22 @@ describe('held message bounds', () => {
|
|||||||
test('is full at its octet cap, until a message leaves by any way out', () => {
|
test('is full at its octet cap, until a message leaves by any way out', () => {
|
||||||
let now = 0;
|
let now = 0;
|
||||||
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 2000, now: () => now, timeout: 10_000 });
|
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 2000, now: () => now, timeout: 10_000 });
|
||||||
const answered = held.hold(message(1), 1);
|
const answered = offer(held, 1);
|
||||||
|
|
||||||
assert.equal(held.full(), false);
|
assert.equal(held.full(), false);
|
||||||
held.hold(message(2), 1);
|
offer(held, 2);
|
||||||
assert.equal(held.full(), true);
|
assert.equal(held.full(), true);
|
||||||
|
|
||||||
answered.release();
|
answered.release();
|
||||||
assert.equal(held.full(), false, 'after a release');
|
assert.equal(held.full(), false, 'after a release');
|
||||||
held.hold(message(3), 1);
|
offer(held, 3);
|
||||||
|
|
||||||
now = 20_000;
|
now = 20_000;
|
||||||
held.sweep();
|
held.sweep();
|
||||||
now = 0;
|
now = 0;
|
||||||
assert.equal(held.full(), false, 'after a sweep');
|
assert.equal(held.full(), false, 'after a sweep');
|
||||||
held.hold(message(4), 1);
|
offer(held, 4);
|
||||||
held.hold(message(5), 1);
|
offer(held, 5);
|
||||||
|
|
||||||
held.clear();
|
held.clear();
|
||||||
assert.equal(held.full(), false, 'after a clear');
|
assert.equal(held.full(), false, 'after a clear');
|
||||||
@@ -1641,11 +1646,11 @@ describe('held message bounds', () => {
|
|||||||
let now = 0;
|
let now = 0;
|
||||||
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 1_000_000, now: () => now, timeout: 60 });
|
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 1_000_000, now: () => now, timeout: 60 });
|
||||||
|
|
||||||
held.hold(message(1), 1);
|
offer(held, 1);
|
||||||
now = 61;
|
now = 61;
|
||||||
|
|
||||||
// The next message sweeps the one that expired, so only the new one is still waited for.
|
// The next message sweeps the one that expired, so only the new one is still waited for.
|
||||||
held.hold(message(2), 1);
|
offer(held, 2);
|
||||||
|
|
||||||
assert.equal(held.size, 1);
|
assert.equal(held.size, 1);
|
||||||
|
|
||||||
@@ -1657,7 +1662,7 @@ describe('held message bounds', () => {
|
|||||||
let now = 0;
|
let now = 0;
|
||||||
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 1_000_000, now: () => now, timeout: 60 });
|
const held = new HeldMessages({ log: silentLog, max: 10, maxOctets: 1_000_000, now: () => now, timeout: 60 });
|
||||||
|
|
||||||
held.hold(message(1), 1);
|
offer(held, 1);
|
||||||
|
|
||||||
const waiting = held.idle(1000, undefined);
|
const waiting = held.idle(1000, undefined);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user