-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtls.ts
More file actions
34 lines (30 loc) · 1.14 KB
/
tls.ts
File metadata and controls
34 lines (30 loc) · 1.14 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
import { expect, test, beforeEach } from "vitest"
import { AMQPClient } from "../src/amqp-socket-client.js"
import { randomBytes } from "crypto"
beforeEach(() => {
expect.hasAssertions()
})
test("can connect with TLS", () => {
const amqp = new AMQPClient(process.env["AMQPS_URL"] || "amqps://127.0.0.1?insecure=true")
return amqp
.connect()
.then((conn) => conn.channel())
.then((ch) => expect(ch.connection.channels.length).toBe(2)) // 2 because channel 0 is counted
})
test("can batch send message", async () => {
const messages = [randomBytes(500), randomBytes(500), randomBytes(500), randomBytes(500)]
const amqp = new AMQPClient("amqps://localhost?insecure=1")
const connection = await amqp.connect()
const channel = await connection.channel()
await channel.queueDeclare("bug137")
await channel.confirmSelect()
const sendMsgs = messages.map((message) =>
channel.basicPublish("", "bug137", JSON.stringify(message), {
contentType: "application/json",
deliveryMode: 2,
}),
)
expect(connection["bufferPool"].length).toBe(0)
await Promise.all(sendMsgs)
expect(connection["bufferPool"].length).toBe(4)
})