k6mult.js
5 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
import ws from 'k6/ws';
import { check } from 'k6';
export const options = {
// vus: 100,
// duration: '30s',
stages: [
{ duration: '60s', target: 10 },
// { duration: '10s', target: 30 },
// { duration: '20s', target: 50 },
],
};
export default function () {
const url = 'ws://localhost:8080';
const params = { tags: { my_tag: 'hello' } };
const res = {};
for (let i = 0; i < 10; i += 1) {
res[i] = ws.connect(`${url}/${i + 1}`, params, (socket) => {
socket.on('open', () => console.log('connected', i));
socket.on('message', (data) => console.log('Message received: ', i));
socket.on('close', () => console.log('disconnected'));
socket.setTimeout(() => {
console.log('60 seconds passed, closing the socket');
socket.close();
}, 60000);
});
}
console.log(res);
check(res, {
'status1 is 101': (r) => r && r[0].status === 101,
'status2 is 101': (r) => r && r[1].status === 101,
'status3 is 101': (r) => r && r[2].status === 101,
'status4 is 101': (r) => r && r[3].status === 101,
});
}
//
// const res1 = ws.connect(`${url}/${1}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 1'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res2 = ws.connect(`${url}/${2}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 2'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res3 = ws.connect(`${url}/${3}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 3'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res4 = ws.connect(`${url}/${4}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 4'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res5 = ws.connect(`${url}/${5}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 5'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res6 = ws.connect(`${url}/${6}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 6'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res7 = ws.connect(`${url}/${7}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 7'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res8 = ws.connect(`${url}/${8}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 8'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res9 = ws.connect(`${url}/${9}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 9'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
//
// const res10 = ws.connect(`${url}/${10}`, params, (socket) => {
// socket.on('open', () => console.log('connected'));
// socket.on('message', (data) => console.log('Message received: 10'));
// socket.on('close', () => console.log('disconnected'));
// socket.setTimeout(() => {
// console.log('60 seconds passed, closing the socket');
// socket.close();
// }, 60000);
// });
// check([res1, res2, res3, res10], { 'status is 101': (r) => r && r.status === 101 });