Repository navigation
Expand file tree
/
Copy pathload_test.js
More file actions
68 lines (60 loc) · 2.53 KB
/
Copy pathload_test.js
File metadata and controls
68 lines (60 loc) · 2.53 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
import ws from 'k6/ws';
import { check } from 'k6';
export const options = {
vus: 20, // Simulate 20 concurrent virtual users
duration: '15s',
};
export default function () {
// Socket.IO v4 endpoint requiring Engine.IO version 4 framing over WebSocket transport
const url = __ENV.TARGET_URL || 'wss://realtime-notes-rzys.onrender.com/socket.io/?EIO=4&transport=websocket';
const res = ws.connect(url, {}, function (socket) {
socket.on('open', () => {
// Connection opened successfully
});
socket.on('message', (msg) => {
// Engine.IO Handshake packet (starts with '0')
if (msg.startsWith('0')) {
// Send Socket.IO namespace connection request (packet type '40')
socket.send('40');
}
// Socket.IO connection acknowledged (starts with '40')
else if (msg.startsWith('40')) {
// Join the shared testing room
const joinPacket = '42' + JSON.stringify([
'join-note',
'benchmark-load-room',
{ email: `load-tester-${__VU}@notesync.io` }
]);
socket.send(joinPacket);
// Simulate continuous vector drawing point broadcasts
socket.setInterval(() => {
const strokePacket = '42' + JSON.stringify([
'draw-progress',
'benchmark-load-room',
{
id: `live-stroke-${__VU}`,
color: '#3b82f6',
strokeWidth: 4,
points: [{ x: Math.floor(Math.random() * 600), y: Math.floor(Math.random() * 600) }]
}
]);
socket.send(strokePacket);
}, 100); // Broadcast every 100ms per user
}
// Engine.IO Heartbeat Ping packet (packet type '2')
else if (msg === '2') {
// Respond with Heartbeat Pong (packet type '3') to keep session alive
socket.send('3');
}
});
socket.on('error', (e) => {
if (e.error() != 'websocket: close sent') {
console.log('An unexpected error occurred: ', e.error());
}
});
socket.setTimeout(function () {
socket.close();
}, 14000);
});
check(res, { 'Connected to Socket.IO successfully': (r) => r && r.status === 101 });
}