-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrain.js
36 lines (31 loc) · 943 Bytes
/
drain.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
const http = require('http')
let drop_goal = 10_000;
let dropped = 0;
let query = {
host: 'localhost',
port: 8080,
path: '/events'
}
setInterval(() => {
if (dropped < drop_goal) {
let request = http.get(query, response => {
response.on('data', data => {
if (data.includes("data: connected\n")) {
// drop connection after welcome message
dropped += 1;
request.abort()
}
})
})
.on('error', () => {})
}
}, 1)
setInterval(() => {
http.get('http://localhost:8080/', () => print_status(true))
.setTimeout(100, () => print_status(false))
.on('error', () => {})
}, 20)
function print_status(accepting_connections) {
process.stdout.write("\r\x1b[K");
process.stdout.write(`Connections dropped: ${dropped}, accepting connections: ${accepting_connections}`);
}