-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathecho.js
38 lines (33 loc) · 1.13 KB
/
echo.js
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
import { check } from "k6";
import cable from "k6/x/cable";
export default function () {
const client = cable.connect("ws://localhost:8080/cable");
const channelPromise = client.subscribeAsync("BenchmarkChannel");
const channel = channelPromise.await();
channel.perform("echo", { foo: 1 });
const res = channel.receive();
check(res, {
"received res": (obj) => obj.foo === 1,
});
channel.perform("echo", { bar: 2 });
const res2 = channel.receive((msg) => msg.bar === 2);
check(res2, {
"received res2": (obj) => obj.bar === 2,
});
channel.perform("echo", { foobar: 3 });
channel.perform("echo", { foobaz: 3 });
channel.perform("echo", { baz: 3 });
const reses = channel.receiveN(3);
check(reses, {
"received 3 messages": (obj) => obj.length === 3,
});
channel.perform("echo", { baz: 3 });
channel.perform("echo", { foobaz: 3 });
channel.perform("echo", { baz: 3, foobaz: 3 });
const reses2 = channel.receiveN(2, { baz: 3 });
check(reses2, {
"received 2 messages": (obj) => obj.length === 2,
"all messages with baz attr": (obj) =>
obj.reduce((r, e) => r && e.baz === 3, true),
});
}