-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathMsgPack.test.ts
53 lines (46 loc) · 1.53 KB
/
MsgPack.test.ts
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
import * as MsgPack from "@effect/experimental/MsgPack"
import * as Socket from "@effect/platform-node/NodeSocket"
import { Chunk, Effect, Stream } from "effect"
import * as Net from "node:net"
import { assert, describe, test } from "vitest"
const server = Net.createServer((socket) => {
socket.on("data", (data) => {
socket.write(data)
})
socket.on("end", () => {
socket.end()
})
})
let port = 0
server.listen({
port: 0
}, () => {
port = (server.address() as Net.AddressInfo).port
})
describe("MsgPack", () => {
test("socket", () =>
Effect.gen(function*(_) {
const socket = Socket.makeNetChannel<MsgPack.MsgPackError>({ port, host: "localhost" }).pipe(
MsgPack.duplex
)
const outputEffect = Stream.make({ hello: "world" }, { test: 123 }).pipe(
Stream.pipeThroughChannel(socket),
Stream.runCollect
)
const output = yield* _(outputEffect)
assert.deepStrictEqual(Chunk.toArray(output), [{ hello: "world" }, { test: 123 }])
}).pipe(Effect.runPromise))
test("socket x10000", () =>
Effect.gen(function*(_) {
const socket = Socket.makeNetChannel<MsgPack.MsgPackError>({ port }).pipe(
MsgPack.duplex
)
const msgs = Array.from({ length: 10000 }, (_, i) => ({ hello: i }))
const outputEffect = Stream.fromIterable(msgs).pipe(
Stream.pipeThroughChannel(socket),
Stream.runCollect
)
const output = yield* _(outputEffect)
assert.deepStrictEqual(Chunk.toArray(output), msgs)
}).pipe(Effect.runPromise))
})