-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
63 lines (52 loc) · 1.11 KB
/
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
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
const http = require("http");
const assert = require("assert");
const congestion = require("./index")();
let port;
let inflight;
let server;
describe("Test congestion", () => {
beforeEach(done => {
server = http.createServer((req, res) => {
inflight = congestion(res);
setTimeout(() => {
res.end();
}, 20);
});
server.listen(0, () => {
port = server.address().port;
done();
});
});
afterEach(done => {
server.close(() => {
done();
});
});
it("measure no of inflight req", done => {
const url = `http://127.0.0.1:${port}`;
Array(2)
.fill(url)
.map(u => {
http.get(u).end();
});
setTimeout(() => {
assert.equal(inflight, 2);
done();
}, 10);
});
it("increment and decrement inflight", done => {
const url = `http://127.0.0.1:${port}`;
const reqs = Array(2)
.fill(url)
.map(u => {
const req = http.get(u);
req.end();
return req;
});
reqs[0].abort();
setTimeout(() => {
assert.equal(inflight, 1);
done();
}, 10);
});
});