-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.test.js
34 lines (27 loc) · 1.09 KB
/
server.test.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
const { describe, it } = require('node:test');
const assert = require('assert');
const axios = require('axios');
const os = require("os");
const serverUrl = 'http://localhost/';
const numberOfRequests = 10000;
const numCPUs = os.cpus().length;
describe('Server functionality tests', () => {
it('should respond to multiple concurrent HTTP GET requests', async () => {
const requests = Array.from({length: numberOfRequests}, () =>
axios.get(serverUrl)
);
const responses = await Promise.all(requests);
responses.forEach(response => {
assert.strictEqual(response.status, 200);
assert.ok(response.data.includes('Hello world!!!'));
});
});
// it('should balance load across workers', async () => {
// const workerResponses = new Set();
// const requests = Array.from({length: numberOfRequests}, () =>
// axios.get(serverUrl).then(response => workerResponses.add(response.data))
// );
// await Promise.all(requests);
// assert.ok(workerResponses.size === numCPUs);
// });
});