test.js
948 Bytes
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
import ws from 'k6/ws';
import { check } from 'k6';
export default function () {
const url = 'ws://echo.websocket.org';
const params = { tags: { my_tag: 'hello' } };
const res = ws.connect(url, params, (socket) => {
socket.on('open', () => {
console.log('connected');
socket.setInterval(() => {
socket.ping();
console.log('Pinging every 1sec (setInterval test)');
}, 1000);
});
socket.on('ping', () => {
console.log('PING!');
});
socket.on('pong', () => {
console.log('PONG!');
});
socket.on('close', () => {
console.log('disconnected');
});
socket.setTimeout(() => {
console.log('2 seconds passed, closing the socket');
socket.close();
}, 2000);
});
check(res, {
'status is 101': (r) => r && r.status === 101,
'Homepage body size is 11026 bytes': (r) => r.body && r.body.length === 11026,
test: (r) => r,
});
}