|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +// Test: listEndpoints returns live endpoints filtered by active state. |
| 4 | +// - Returns an empty array when no endpoints exist. |
| 5 | +// - Includes all created endpoints. |
| 6 | +// - active=true (default) filters out destroyed, closing, and busy endpoints. |
| 7 | +// - active=false returns all registered endpoints regardless of state. |
| 8 | +// - Validates options argument types. |
| 9 | + |
| 10 | +import{hasQuic,skip}from'../common/index.mjs'; |
| 11 | +importassertfrom'node:assert'; |
| 12 | + |
| 13 | +const{ deepStrictEqual, strictEqual, throws, ok }=assert; |
| 14 | + |
| 15 | +if(!hasQuic){ |
| 16 | +skip('QUIC is not enabled'); |
| 17 | +} |
| 18 | + |
| 19 | +const{ listEndpoints, QuicEndpoint }=awaitimport('node:quic'); |
| 20 | + |
| 21 | +// listEndpoints is exported as a function. |
| 22 | +strictEqual(typeoflistEndpoints,'function'); |
| 23 | + |
| 24 | +// Empty when no endpoints have been created. |
| 25 | +deepStrictEqual(listEndpoints(),[]); |
| 26 | +deepStrictEqual(listEndpoints({active: false}),[]); |
| 27 | + |
| 28 | +// Created endpoints appear in the list. |
| 29 | +{ |
| 30 | +constep1=newQuicEndpoint(); |
| 31 | +constep2=newQuicEndpoint(); |
| 32 | + |
| 33 | +constlist=listEndpoints(); |
| 34 | +strictEqual(list.length,2); |
| 35 | +ok(list.includes(ep1)); |
| 36 | +ok(list.includes(ep2)); |
| 37 | + |
| 38 | +// active=false also returns them. |
| 39 | +constall=listEndpoints({active: false}); |
| 40 | +strictEqual(all.length,2); |
| 41 | +ok(all.includes(ep1)); |
| 42 | +ok(all.includes(ep2)); |
| 43 | + |
| 44 | +// Returns plain QuicEndpoint instances, not wrapped in arrays. |
| 45 | +ok(list[0]instanceofQuicEndpoint); |
| 46 | +ok(list[1]instanceofQuicEndpoint); |
| 47 | + |
| 48 | +awaitep1.close(); |
| 49 | +awaitep2.close(); |
| 50 | +} |
| 51 | + |
| 52 | +// Destroyed endpoints are excluded by active filter. |
| 53 | +{ |
| 54 | +constep=newQuicEndpoint(); |
| 55 | +strictEqual(listEndpoints().length,1); |
| 56 | + |
| 57 | +awaitep.close(); |
| 58 | +awaitep.closed; |
| 59 | +strictEqual(ep.destroyed,true); |
| 60 | + |
| 61 | +// Default (active=true) excludes destroyed endpoint. |
| 62 | +strictEqual(listEndpoints().length,0); |
| 63 | + |
| 64 | +// active=false still includes it... but destroyed endpoints are removed |
| 65 | +// from the registry entirely in kFinishClose, so it won't appear at all. |
| 66 | +strictEqual(listEndpoints({active: false}).length,0); |
| 67 | +} |
| 68 | + |
| 69 | +// Busy endpoints are excluded by the active filter. |
| 70 | +{ |
| 71 | +constep=newQuicEndpoint(); |
| 72 | +strictEqual(listEndpoints().length,1); |
| 73 | + |
| 74 | +ep.busy=true; |
| 75 | +strictEqual(ep.busy,true); |
| 76 | + |
| 77 | +// active=true excludes busy endpoint. |
| 78 | +strictEqual(listEndpoints().length,0); |
| 79 | + |
| 80 | +// active=false includes it. |
| 81 | +constall=listEndpoints({active: false}); |
| 82 | +strictEqual(all.length,1); |
| 83 | +ok(all.includes(ep)); |
| 84 | + |
| 85 | +ep.busy=false; |
| 86 | + |
| 87 | +// After un-busying, it reappears in the active list. |
| 88 | +strictEqual(listEndpoints().length,1); |
| 89 | + |
| 90 | +awaitep.close(); |
| 91 | +} |
| 92 | + |
| 93 | +// Options validation. |
| 94 | +throws(()=>listEndpoints('bad'),{ |
| 95 | +code: 'ERR_INVALID_ARG_TYPE', |
| 96 | +}); |
| 97 | +throws(()=>listEndpoints(null),{ |
| 98 | +code: 'ERR_INVALID_ARG_TYPE', |
| 99 | +}); |
| 100 | +throws(()=>listEndpoints({active: 'yes'}),{ |
| 101 | +code: 'ERR_INVALID_ARG_TYPE', |
| 102 | +}); |
| 103 | +throws(()=>listEndpoints({active: 1}),{ |
| 104 | +code: 'ERR_INVALID_ARG_TYPE', |
| 105 | +}); |
0 commit comments