forked from StellarDevHub/Web3-Student-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathws-load-test.js
More file actions
40 lines (37 loc) · 1.22 KB
/
Copy pathws-load-test.js
File metadata and controls
40 lines (37 loc) · 1.22 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
const autocannon = require('autocannon');
const url = process.env.TEST_URL || 'http://localhost:4001/graphql';
const connections = Number(process.env.CONNS || 1000);
const duration = Number(process.env.DURATION || 10);
console.log(`Starting WS load test against ${url} with ${connections} connections for ${duration}s`);
autocannon({
url,
connections,
duration,
pipelining: 1,
timeout: 20,
headers: { Connection: 'Upgrade', Upgrade: 'websocket' },
setupClient: (client) => {
client.on('connect', () => {
// send a simple graphql-ws connection_init
client.send(JSON.stringify({ type: 'connection_init', payload: {} }));
// send a small subscribe payload for courseUpdated with random id
const id = Math.random().toString(36).slice(2, 8);
const payload = {
id,
type: 'start',
payload: {
query: 'subscription($courseId: ID!){ courseUpdated(courseId: $courseId){ id title } }',
variables: { courseId: 'test-room' },
},
};
client.send(JSON.stringify(payload));
});
client.on('data', () => {});
},
}, (err, res) => {
if (err) {
console.error('autocannon error', err);
process.exit(1);
}
console.log('Finished', res);
});