-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstress_test.js
More file actions
39 lines (31 loc) · 1.03 KB
/
Copy pathstress_test.js
File metadata and controls
39 lines (31 loc) · 1.03 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
import {request} from 'http'; // or 'https' if your server uses SSL
const options = {
hostname: 'localhost', // Replace with your server's hostname
port: 3000, // Replace with your server's port
path: '/bundle.js', // Replace with the path you want to test
method: 'GET', // Or 'POST', 'PUT', etc. depending on your use case
};
const makeRequest = () => {
const req = request(options, (res) => {
// Collect response data
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(`Response: ${res.statusCode} - ${data}`);
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
req.end();
};
// Number of concurrent requests
const numRequests = 1000;
// Interval between each request in milliseconds
const interval = 10;
// Stress testing loop
for (let i = 0; i < numRequests; i++) {
setTimeout(makeRequest, i * interval);
}