Skip to content

Commit 5674670

Browse files
authored
test: add socket checker test case (#341)
#339 (comment)
1 parent d953ec0 commit 5674670

File tree

5 files changed

+75
-8
lines changed

5 files changed

+75
-8
lines changed

.github/workflows/nodejs.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,35 @@ on:
88
branches: [ master ]
99
pull_request:
1010
branches: [ master ]
11+
schedule:
12+
- cron: '0 2 * * *'
1113

1214
jobs:
1315
build:
14-
1516
runs-on: ${{ matrix.os }}
1617

1718
strategy:
19+
fail-fast: false
1820
matrix:
19-
node-version: [6.x, 8.x, 10.x, 12.x, 14.x]
21+
node-version: [8, 10, 12, 14]
2022
os: [ubuntu-latest, windows-latest, macos-latest]
2123

2224
steps:
23-
- uses: actions/checkout@v2
25+
- name: Checkout Git Source
26+
uses: actions/checkout@v2
27+
2428
- name: Use Node.js ${{ matrix.node-version }}
2529
uses: actions/setup-node@v1
2630
with:
2731
node-version: ${{ matrix.node-version }}
28-
- run: npm i -g npminstall && npminstall
29-
- run: npm run ci
30-
env:
31-
CI: true
32+
33+
- name: Install Dependencies
34+
run: npm i -g npminstall && npminstall
35+
36+
- name: Continuous Integration
37+
run: npm run ci
38+
39+
- name: Code Coverage
40+
uses: codecov/codecov-action@v1
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}

.jshintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ examples/
88
lib/get_proxy_from_uri.js
99
test/fixtures/reverse-proxy.js
1010
test/typescript
11+
test/check-socket.js

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"os": {
8484
"github": "linux, windows, macos"
8585
},
86-
"version": "6, 8, 10, 12, 14"
86+
"version": "8, 10, 12, 14"
8787
},
8888
"license": "MIT"
8989
}

test/check-socket.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const Agent = require('agentkeepalive');
5+
const urllib = require('..');
6+
const server = require('./fixtures/server');
7+
8+
describe('test/check-socket.js', () => {
9+
let host = 'http://127.0.0.1:';
10+
before(done => {
11+
server.listen(0, () => {
12+
const port = server.address().port;
13+
host += port;
14+
done();
15+
});
16+
});
17+
18+
after(done => {
19+
setTimeout(() => {
20+
server.close();
21+
done();
22+
}, 1000);
23+
});
24+
25+
it('should get socket on res or req', async () => {
26+
const keepaliveAgent = new Agent({
27+
maxSockets: 1000,
28+
maxFreeSockets: 100,
29+
timeout: 1200000,
30+
freeSocketTimeout: 60000,
31+
});
32+
33+
async function sendMessage(url, data, method = 'GET') {
34+
const res = await urllib.request(url, {
35+
method,
36+
data,
37+
nestedQuerystring: true,
38+
timeout: 60000,
39+
agent: keepaliveAgent,
40+
contentType: 'json',
41+
});
42+
43+
console.log(res.data.toString());
44+
};
45+
46+
await sendMessage(host);
47+
});
48+
});

test/check-socket.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
var major = parseInt(process.version.split('.')[0].substring(1));
4+
5+
if (major >= 8) {
6+
require('./check-socket');
7+
}

0 commit comments

Comments
 (0)