-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathamqp-session.ts
More file actions
684 lines (516 loc) · 22.2 KB
/
amqp-session.ts
File metadata and controls
684 lines (516 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
import { expect, test, vi, beforeEach } from "vitest"
import { AMQPClient } from "../src/amqp-socket-client.js"
import { AMQPSession } from "../src/amqp-session.js"
import { AMQPQueue } from "../src/amqp-queue.js"
import { AMQPExchange } from "../src/amqp-exchange.js"
import { AMQPMessage } from "../src/amqp-message.js"
import type { AMQPBaseClient } from "../src/amqp-base-client.js"
beforeEach(() => {
expect.hasAssertions()
})
/** Access the private client for test-only operations (socket destruction, spying). */
function testClient(session: AMQPSession): AMQPBaseClient {
return (session as unknown as { client: AMQPBaseClient }).client
}
async function withSession(
fn: (session: AMQPSession) => Promise<void>,
options?: Parameters<typeof AMQPSession.connect>[1],
): Promise<void> {
const session = await AMQPSession.connect("amqp://127.0.0.1", options)
try {
await fn(session)
} finally {
await session.stop()
}
}
test("AMQPSession.connect() returns a session", () =>
withSession(
async (session) => {
expect(session).toBeInstanceOf(AMQPSession)
},
{ reconnectInterval: 500 },
))
test("session.subscribe delivers messages via callback", () =>
withSession(async (session) => {
const q = await session.queue("test-queue-" + Math.random(), { durable: false, autoDelete: true })
let messageReceived = false
const sub = await q.subscribe({ noAck: true }, async () => {
messageReceived = true
})
await q.publish("test", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 100))
expect(messageReceived).toBe(true)
await sub.cancel()
}))
test("session.subscribe accepts a broker-named queue", () =>
withSession(async (session) => {
const q = await session.queue("", { durable: false, autoDelete: true })
let messageReceived = false
const sub = await q.subscribe({ noAck: true }, async () => {
messageReceived = true
})
await q.publish("test", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 100))
expect(messageReceived).toBe(true)
await sub.cancel()
}))
test("subscription.cancel() removes it from session recovery", () =>
withSession(async (session) => {
const q = await session.queue("test-cancel-" + Math.random(), { durable: false, autoDelete: true })
const sub = await q.subscribe({ noAck: true }, () => {})
await expect(sub.cancel()).resolves.toBeUndefined()
}))
test("session.subscribe supports prefetch option", () =>
withSession(async (session) => {
const q = await session.queue("test-prefetch-queue-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("message 1", { confirm: false })
await q.publish("message 2", { confirm: false })
await q.publish("message 3", { confirm: false })
const received: string[] = []
const sub = await q.subscribe({ prefetch: 1 }, async (msg) => {
received.push(msg.bodyString() ?? "")
})
await new Promise((resolve) => setTimeout(resolve, 200))
expect(received).toEqual(["message 1", "message 2", "message 3"])
await sub.cancel()
}))
test("session.subscribe yields messages via async generator", () =>
withSession(async (session) => {
const q = await session.queue("test-generator-" + Math.random(), { durable: false, autoDelete: true })
const sub = await q.subscribe({ noAck: true })
await q.publish("msg1", { confirm: false })
await q.publish("msg2", { confirm: false })
const received: string[] = []
for await (const msg of sub) {
received.push(msg.bodyString()!)
if (received.length >= 2) break
}
expect(received).toEqual(["msg1", "msg2"])
await sub.cancel()
}))
test("session.onfailed fires when maxRetries exhausted", () =>
withSession(
async (session) => {
const onfailed = vi.fn()
session.onfailed = onfailed
const client = testClient(session)
const connectSpy = vi.spyOn(client, "connect").mockRejectedValue(new Error("forced failure"))
;(client as AMQPClient).socket?.destroy()
// Wait long enough for 2 retries + backoff (50ms + 100ms) with buffer
await new Promise((resolve) => setTimeout(resolve, 500))
expect(onfailed).toHaveBeenCalledTimes(1)
expect(onfailed.mock.calls[0]?.[0]).toBeInstanceOf(Error)
expect(connectSpy).toHaveBeenCalledTimes(2)
connectSpy.mockRestore()
},
{ reconnectInterval: 50, maxRetries: 2 },
))
test("session.onconnect fires after successful reconnection", () =>
withSession(
async (session) => {
let reconnectCount = 0
const reconnected = new Promise<void>((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error("onconnect did not fire within 5s")), 5_000)
session.onconnect = () => {
clearTimeout(timeout)
reconnectCount++
resolve()
}
})
;(testClient(session) as AMQPClient).socket?.destroy()
await reconnected
expect(reconnectCount).toBe(1)
},
{ reconnectInterval: 50, maxRetries: 5 },
))
test("subscription recovers and receives messages after reconnection", () =>
withSession(
async (session) => {
const q = await session.queue("test-recovery-" + Math.random(), { durable: false, autoDelete: false })
const received: string[] = []
const sub = await q.subscribe({ noAck: true }, (msg) => {
received.push(msg.bodyString() || "")
})
// Publish a message before disconnect
await q.publish("before-disconnect", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 100))
const reconnected = new Promise<void>((resolve, reject) => {
const timeout = setTimeout(() => reject(new Error("Reconnection timed out")), 10_000)
session.onconnect = () => {
clearTimeout(timeout)
resolve()
}
})
;(testClient(session) as AMQPClient).socket?.destroy()
await reconnected
// Publish a message after reconnection
await q.publish("after-reconnect", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 200))
expect(received).toContain("before-disconnect")
expect(received).toContain("after-reconnect")
// Verify the subscription object is the same reference and channel is live
expect(sub.channel.closed).toBe(false)
await sub.cancel()
await q.delete()
},
{ reconnectInterval: 50, maxRetries: 5 },
))
test("session.stop() during reconnection stops the loop", () =>
withSession(
async (session) => {
const client = testClient(session)
const connectSpy = vi.spyOn(client, "connect").mockRejectedValue(new Error("forced failure"))
;(client as AMQPClient).socket?.destroy()
// Stop before the first reconnection attempt fires
await new Promise((resolve) => setTimeout(resolve, 50))
await session.stop()
// Confirm no further reconnection attempts
await new Promise((resolve) => setTimeout(resolve, 500))
expect(connectSpy.mock.calls.length).toBeLessThanOrEqual(1)
connectSpy.mockRestore()
},
{ reconnectInterval: 200, maxRetries: 10 },
))
test("session.stop() when already disconnected does not throw", () =>
withSession(
async (session) => {
;(testClient(session) as AMQPClient).socket?.destroy()
await new Promise((resolve) => setTimeout(resolve, 50))
await expect(session.stop()).resolves.toBeUndefined()
},
{ maxRetries: 1 },
))
test("session.queue() declares a queue and returns AMQPQueue", () =>
withSession(async (session) => {
const q = await session.queue("test-sq-" + Math.random(), { durable: false, autoDelete: true })
expect(q).toBeInstanceOf(AMQPQueue)
expect(q.name).toMatch(/^test-sq-/)
}))
test("AMQPQueue (session-backed).publish() and get() round-trip", () =>
withSession(async (session) => {
const q = await session.queue("test-sq-rtt-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("round-trip")
const msg = await q.get({ noAck: true })
expect(msg?.bodyString()).toBe("round-trip")
}))
test("AMQPQueue (session-backed).subscribe() recovers after reconnect", () =>
withSession(
async (session) => {
const qName = "test-sq-recovery-" + Math.random()
const q = await session.queue(qName, { durable: false, autoDelete: false })
const received: string[] = []
const sub = await q.subscribe({ noAck: true }, (msg) => {
received.push(msg.bodyString() ?? "")
})
await q.publish("before-disconnect")
await new Promise((resolve) => setTimeout(resolve, 100))
const reconnected = new Promise<void>((resolve, reject) => {
const t = setTimeout(() => reject(new Error("reconnect timed out")), 10_000)
session.onconnect = () => {
clearTimeout(t)
resolve()
}
})
;(testClient(session) as AMQPClient).socket?.destroy()
await reconnected
await q.publish("after-reconnect")
await new Promise((resolve) => setTimeout(resolve, 200))
expect(received).toContain("before-disconnect")
expect(received).toContain("after-reconnect")
await sub.cancel()
await q.delete()
},
{ reconnectInterval: 50, maxRetries: 5 },
))
test("session.exchange() declares an exchange and returns AMQPExchange", () =>
withSession(async (session) => {
const xName = "test-exchange-" + Math.random()
const x = await session.exchange(xName, "direct", { durable: false, autoDelete: true })
expect(x).toBeInstanceOf(AMQPExchange)
expect(x.name).toBe(xName)
await x.delete()
}))
test("session.fanoutExchange() publishes to all bound queues", () =>
withSession(async (session) => {
const xName = "test-fanout-" + Math.random()
const qName = "test-fanout-q-" + Math.random()
const x = await session.fanoutExchange(xName, { durable: false, autoDelete: true })
const q = await session.queue(qName, { durable: false, autoDelete: true })
await q.bind(xName, "")
await x.publish("fanout msg")
await new Promise((resolve) => setTimeout(resolve, 100))
const msg = await q.get({ noAck: true })
expect(msg?.bodyString()).toBe("fanout msg")
}))
test("session.topicExchange() routes by pattern", () =>
withSession(async (session) => {
const xName = "test-topic-" + Math.random()
const qName = "test-topic-q-" + Math.random()
const x = await session.topicExchange(xName, { durable: false, autoDelete: true })
const q = await session.queue(qName, { durable: false, autoDelete: true })
await q.bind(xName, "events.#")
await x.publish("topic msg", { routingKey: "events.user.created" })
await new Promise((resolve) => setTimeout(resolve, 100))
const msg = await q.get({ noAck: true })
expect(msg?.bodyString()).toBe("topic msg")
}))
test("session.directExchange('') returns the default exchange handle", () =>
withSession(async (session) => {
const qName = "test-default-x-" + Math.random()
const x = await session.directExchange("")
expect(x.name).toBe("")
const q = await session.queue(qName, { durable: false, autoDelete: true })
await x.publish("via default exchange", { routingKey: qName })
await new Promise((resolve) => setTimeout(resolve, 100))
const msg = await q.get({ noAck: true })
expect(msg?.bodyString()).toBe("via default exchange")
}))
test("AMQPExchange.bind() and unbind() work", () =>
withSession(async (session) => {
const srcName = "test-xe-src-" + Math.random()
const dstName = "test-xe-dst-" + Math.random()
const src = await session.fanoutExchange(srcName, { durable: false, autoDelete: true })
const dst = await session.fanoutExchange(dstName, { durable: false, autoDelete: true })
await expect(dst.bind(src)).resolves.toBeInstanceOf(AMQPExchange)
await expect(dst.unbind(src)).resolves.toBeInstanceOf(AMQPExchange)
}))
test("AMQPExchange.delete() removes the exchange", () =>
withSession(async (session) => {
const xName = "test-del-x-" + Math.random()
const x = await session.exchange(xName, "direct", { durable: false, autoDelete: false })
await expect(x.delete()).resolves.toBeUndefined()
}))
test("AMQPQueue.subscribe() delivers messages via callback", () =>
withSession(async (session) => {
const q = await session.queue("test-q-sub-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("hello queue")
const received = await new Promise<string>((resolve) => {
q.subscribe({ noAck: true }, (msg) => resolve(msg.bodyString()!))
})
expect(received).toBe("hello queue")
}))
test("AMQPQueue.subscribe() nack", () =>
withSession(async (session) => {
const q = await session.queue("test-q-nack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("nack me")
const msg = await new Promise<AMQPMessage>((resolve) => {
q.subscribe({ noAck: false }, (m) => {
m.nack()
resolve(m)
})
})
expect(msg.bodyString()).toBe("nack me")
}))
test("AMQPQueue.subscribe() async generator", () =>
withSession(async (session) => {
const q = await session.queue("test-q-gen-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("msg1")
await q.publish("msg2")
const received: string[] = []
const sub = await q.subscribe({ noAck: true })
for await (const msg of sub) {
received.push(msg.bodyString()!)
if (received.length >= 2) break
}
expect(received).toEqual(["msg1", "msg2"])
}))
test("AMQPQueue.publish({ confirm: false }) sends without waiting for confirm", () =>
withSession(async (session) => {
const q = await session.queue("test-q-paf-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("fire and forget", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 50))
const msg = await q.get({ noAck: true })
expect(msg?.bodyString()).toBe("fire and forget")
}))
test("AMQPQueue.bind() and unbind()", () =>
withSession(async (session) => {
const q = await session.queue("test-q-bind-" + Math.random(), { durable: false, autoDelete: true })
await expect(q.bind("amq.topic", "test.key")).resolves.toBeInstanceOf(AMQPQueue)
await expect(q.unbind("amq.topic", "test.key")).resolves.toBeInstanceOf(AMQPQueue)
}))
test("AMQPQueue.purge() empties the queue", () =>
withSession(async (session) => {
const q = await session.queue("test-q-purge-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("msg1", { confirm: false })
await q.publish("msg2", { confirm: false })
await new Promise((resolve) => setTimeout(resolve, 50))
const result = await q.purge()
expect(result.messageCount).toBe(2)
}))
test("AMQPQueue.delete() removes the queue", () =>
withSession(async (session) => {
const q = await session.queue("test-q-del-" + Math.random(), { durable: false, autoDelete: false })
await expect(q.delete()).resolves.toBeDefined()
}))
test("AMQPQueue.subscribe() acks message after callback returns", () =>
withSession(async (session) => {
const q = await session.queue("test-autoack-default-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("hello")
const ackSpy = vi.spyOn(AMQPMessage.prototype, "ack")
const received: string[] = []
const sub = await q.subscribe(async (msg) => {
received.push(msg.bodyString() ?? "")
})
await new Promise((resolve) => setTimeout(resolve, 100))
expect(received).toEqual(["hello"])
expect(ackSpy).toHaveBeenCalledOnce()
ackSpy.mockRestore()
await sub.cancel()
}))
test("AMQPQueue.subscribe() acks message after successful callback with prefetch", () =>
withSession(async (session) => {
const q = await session.queue("test-autoack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("hello")
const ackSpy = vi.spyOn(AMQPMessage.prototype, "ack")
const received: string[] = []
const sub = await q.subscribe({ prefetch: 1 }, async (msg) => {
received.push(msg.bodyString() ?? "")
})
await new Promise((resolve) => setTimeout(resolve, 100))
expect(received).toEqual(["hello"])
expect(ackSpy).toHaveBeenCalledOnce()
ackSpy.mockRestore()
await sub.cancel()
}))
test("AMQPQueue.subscribe() nacks message when callback throws", () =>
withSession(async (session) => {
const q = await session.queue("test-autoack-nack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("fail")
const nackSpy = vi.spyOn(AMQPMessage.prototype, "nack")
let callCount = 0
const sub = await q.subscribe({ requeueOnNack: false, prefetch: 1 }, async () => {
callCount++
throw new Error("boom")
})
await new Promise((resolve) => setTimeout(resolve, 100))
expect(callCount).toBe(1)
expect(nackSpy).toHaveBeenCalledWith(false)
nackSpy.mockRestore()
await sub.cancel()
}))
test("AMQPQueue.subscribe() does not ack when noAck is true", () =>
withSession(async (session) => {
const q = await session.queue("test-autoack-noack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("hi")
const ackSpy = vi.spyOn(AMQPMessage.prototype, "ack")
const received: string[] = []
const sub = await q.subscribe({ noAck: true, prefetch: 1 }, async (msg) => {
received.push(msg.bodyString() ?? "")
})
await new Promise((resolve) => setTimeout(resolve, 100))
expect(received).toEqual(["hi"])
expect(ackSpy).not.toHaveBeenCalled()
ackSpy.mockRestore()
await sub.cancel()
}))
test("AMQPQueue.subscribe() async iterator auto-acks on advance", () =>
withSession(async (session) => {
const q = await session.queue("test-iter-autoack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("msg1")
await q.publish("msg2")
const msgs: AMQPMessage[] = []
const sub = await q.subscribe()
for await (const msg of sub) {
msgs.push(msg)
if (msgs.length >= 2) break
}
// msg1 was auto-acked when the loop advanced to msg2; msg2 was not (loop broke)
expect(msgs[0]!.isAcked).toBe(true)
expect(msgs[1]!.isAcked).toBe(false)
await sub.cancel()
}))
test("AMQPQueue.subscribe() async iterator does not ack when noAck is true", () =>
withSession(async (session) => {
const q = await session.queue("test-iter-noack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("msg1")
await q.publish("msg2")
const msgs: AMQPMessage[] = []
const sub = await q.subscribe({ noAck: true })
for await (const msg of sub) {
msgs.push(msg)
if (msgs.length >= 2) break
}
expect(msgs[0]!.isAcked).toBe(false)
expect(msgs[1]!.isAcked).toBe(false)
await sub.cancel()
}))
test("AMQPQueue.subscribe() async iterator does not double-ack if message already acked", () =>
withSession(async (session) => {
const q = await session.queue("test-iter-double-ack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("msg1")
await q.publish("msg2")
const { AMQPChannel } = await import("../src/amqp-channel.js")
const basicAckSpy = vi.spyOn(AMQPChannel.prototype, "basicAck")
const sub = await q.subscribe()
for await (const msg of sub) {
await msg.ack() // manual ack inside the loop
if (basicAckSpy.mock.calls.length >= 1) break
}
// Only one wire call despite auto-ack also running
expect(basicAckSpy).toHaveBeenCalledOnce()
basicAckSpy.mockRestore()
await sub.cancel()
}))
test("AMQPQueue.subscribe() does not double-ack if callback already acked", () =>
withSession(async (session) => {
const q = await session.queue("test-no-double-ack-" + Math.random(), { durable: false, autoDelete: true })
await q.publish("hello")
const { AMQPChannel } = await import("../src/amqp-channel.js")
const basicAckSpy = vi.spyOn(AMQPChannel.prototype, "basicAck")
const sub = await q.subscribe(async (msg) => {
await msg.ack()
})
await new Promise((resolve) => setTimeout(resolve, 100))
expect(basicAckSpy).toHaveBeenCalledOnce()
basicAckSpy.mockRestore()
await sub.cancel()
}))
test("session.rpcClient() and session.rpcServer() round-trip", () =>
withSession(async (session) => {
await session.rpcServer("rpc-test-queue", (msg) => {
return `reply:${msg.bodyString()}`
})
const rpc = await session.rpcClient()
const reply = await rpc.call("rpc-test-queue", "hello")
expect(reply.bodyString()).toEqual("reply:hello")
await session.queue("rpc-test-queue").then((q) => q.delete())
}))
test("session.rpcClient() can do multiple calls", () =>
withSession(async (session) => {
await session.rpcServer("rpc-multi-queue", (msg) => {
return `re:${msg.bodyString()}`
})
const rpc = await session.rpcClient()
const r1 = await rpc.call("rpc-multi-queue", "a")
expect(r1.bodyString()).toEqual("re:a")
const r2 = await rpc.call("rpc-multi-queue", "b")
expect(r2.bodyString()).toEqual("re:b")
await session.queue("rpc-multi-queue").then((q) => q.delete())
}))
test("session.rpcCall() one-shot round-trip", () =>
withSession(async (session) => {
await session.rpcServer("rpc-oneshot-queue", (msg) => {
return `got:${msg.bodyString()}`
})
const reply = await session.rpcCall("rpc-oneshot-queue", "ping")
expect(reply.bodyString()).toEqual("got:ping")
await session.queue("rpc-oneshot-queue").then((q) => q.delete())
}))
test("session.rpcClient() rejects on timeout", () =>
withSession(async (session) => {
// Declare queue so the message routes somewhere, but no consumer to reply
await session.queue("rpc-timeout-queue")
const rpc = await session.rpcClient()
await expect(rpc.call("rpc-timeout-queue", "hello", { timeout: 100 })).rejects.toThrow(/No response received/)
await session.queue("rpc-timeout-queue").then((q) => q.delete())
}))
test("session.rpcClient() close rejects pending calls", () =>
withSession(async (session) => {
await session.queue("rpc-close-queue")
const rpc = await session.rpcClient()
const pending = rpc.call("rpc-close-queue", "hello")
const expectRejection = expect(pending).rejects.toThrow(/RPC client closed/)
await rpc.close()
await expectRejection
await session.queue("rpc-close-queue").then((q) => q.delete())
}))