-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
216 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/fixtures/ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
Thank you for your pull request. Please review below requirements. | ||
Bug fixes and new features should include tests and possibly benchmarks. | ||
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md | ||
感谢您贡献代码。请确认下列 checklist 的完成情况。 | ||
Bug 修复和新功能必须包含测试,必要时请附上性能测试。 | ||
Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md | ||
--> | ||
|
||
##### Checklist | ||
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> | ||
|
||
- [ ] `npm test` passes | ||
- [ ] tests and/or benchmarks are included | ||
- [ ] documentation is changed or added | ||
- [ ] commit message follows commit guidelines | ||
|
||
##### Affected core subsystem(s) | ||
<!-- Provide affected core subsystem(s). --> | ||
|
||
|
||
##### Description of change | ||
<!-- Provide a description of the change below this comment. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
node-version: [8.x, 10.x, 12.x] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm i -g npminstall && npminstall | ||
- run: npm run ci | ||
env: | ||
CI: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ node_modules | |
npm-debug.log | ||
coverage/ | ||
.nyc_output/ | ||
test/fixtures/ts/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,62 @@ | ||
declare module "agentkeepalive" { | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
|
||
interface PlainObject { | ||
[key: string]: any; | ||
} | ||
|
||
declare class HttpAgent extends http.Agent { | ||
constructor(opts?: AgentKeepAlive.HttpOptions); | ||
readonly statusChanged: boolean; | ||
createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void; | ||
getCurrentStatus(): AgentKeepAlive.AgentStatus; | ||
} | ||
|
||
interface Constants { | ||
CURRENT_ID: Symbol; | ||
CREATE_ID: Symbol; | ||
INIT_SOCKET: Symbol; | ||
CREATE_HTTPS_CONNECTION: Symbol; | ||
SOCKET_CREATED_TIME: Symbol; | ||
SOCKET_NAME: Symbol; | ||
SOCKET_REQUEST_COUNT: Symbol; | ||
SOCKET_REQUEST_FINISHED_COUNT: Symbol; | ||
} | ||
|
||
declare class AgentKeepAlive extends HttpAgent {} | ||
|
||
declare namespace AgentKeepAlive { | ||
export interface AgentStatus { | ||
createSocketCount: number, | ||
createSocketErrorCount: number, | ||
closeSocketCount: number, | ||
errorSocketCount: number, | ||
timeoutSocketCount: number, | ||
requestCount: number, | ||
freeSockets: object, | ||
sockets: object, | ||
requests: object, | ||
createSocketCount: number; | ||
createSocketErrorCount: number; | ||
closeSocketCount: number; | ||
errorSocketCount: number; | ||
timeoutSocketCount: number; | ||
requestCount: number; | ||
freeSockets: PlainObject; | ||
sockets: PlainObject; | ||
requests: PlainObject; | ||
} | ||
|
||
export interface HttpOptions extends http.AgentOptions { | ||
interface CommonHttpOption { | ||
keepAlive?: boolean; | ||
freeSocketTimeout?: number; | ||
freeSocketKeepAliveTimeout?: number; | ||
timeout?: number; | ||
socketActiveTTL?: number; | ||
} | ||
|
||
export interface HttpsOptions extends https.AgentOptions { | ||
keepAlive?: boolean; | ||
freeSocketTimeout?: number; | ||
freeSocketKeepAliveTimeout?: number; | ||
timeout?: number; | ||
socketActiveTTL?: number; | ||
} | ||
export interface HttpOptions extends http.AgentOptions, CommonHttpOption { } | ||
export interface HttpsOptions extends https.AgentOptions, CommonHttpOption { } | ||
|
||
export default class HttpAgent extends http.Agent { | ||
export class HttpsAgent extends https.Agent { | ||
constructor(opts?: HttpOptions); | ||
readonly statusChanged: boolean; | ||
createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void; | ||
getCurrentStatus(): AgentStatus; | ||
} | ||
|
||
export class HttpsAgent extends https.Agent { | ||
constructor(opts?: HttpsOptions); | ||
readonly statusChanged: boolean; | ||
createSocket(req: http.IncomingMessage, options: https.RequestOptions, cb: Function): void; | ||
getCurrentStatus(): AgentStatus; | ||
} | ||
export const constants: Constants; | ||
} | ||
|
||
export = AgentKeepAlive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import http from 'http'; | ||
import Agent from '../../..'; | ||
import assert from 'assert'; | ||
|
||
const constants = Agent.constants; | ||
assert(constants.CREATE_ID); | ||
assert(constants.CREATE_HTTPS_CONNECTION); | ||
assert(constants.CURRENT_ID); | ||
|
||
const httpOpt: Agent.HttpOptions = { | ||
maxSockets: 100, | ||
maxFreeSockets: 10, | ||
timeout: 60000, // active socket keepalive for 60 seconds | ||
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds | ||
}; | ||
const keepaliveAgent = new Agent(httpOpt); | ||
|
||
const options = { | ||
host: 'cnodejs.org', | ||
port: 80, | ||
path: '/', | ||
method: 'GET', | ||
agent: keepaliveAgent, | ||
}; | ||
|
||
const req = http.request(options, res => { | ||
console.log('STATUS: ' + res.statusCode); | ||
console.log('HEADERS: ' + JSON.stringify(res.headers)); | ||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
console.log('BODY: ' + chunk); | ||
}); | ||
}); | ||
|
||
req.on('error', e => { | ||
console.log('problem with request: ' + e.message); | ||
}); | ||
|
||
req.end(); | ||
|
||
setTimeout(() => { | ||
if (keepaliveAgent.statusChanged) { | ||
const httpAgentStatus: Agent.AgentStatus = keepaliveAgent.getCurrentStatus(); | ||
console.log('[%s] agent status changed: %j', Date(), httpAgentStatus); | ||
} | ||
}, 2000); | ||
|
||
// https | ||
const HttpsAgent = Agent.HttpsAgent; | ||
const httpsOpt: Agent.HttpsOptions = { | ||
maxSockets: 100, | ||
maxFreeSockets: 10, | ||
timeout: 60000, // active socket keepalive for 60 seconds | ||
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds | ||
}; | ||
const keepaliveHttpsAgent = new HttpsAgent(httpsOpt); | ||
const httpsAgentStatus: Agent.AgentStatus = keepaliveHttpsAgent.getCurrentStatus(); | ||
assert(httpsAgentStatus); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "commonjs", | ||
"noImplicitAny": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"charset": "utf8", | ||
"allowJs": false, | ||
"pretty": false, | ||
"baseUrl": ".", | ||
"strict": true, | ||
"resolveJsonModule": true, | ||
"noEmitOnError": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": true, | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"skipLibCheck": false, | ||
"skipDefaultLibCheck": false, | ||
"importHelpers": false, | ||
"inlineSourceMap": true, | ||
"esModuleInterop": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const coffee = require('coffee'); | ||
|
||
describe('test/ts.test.js', () => { | ||
it('should compile ts and run without error', async () => { | ||
await coffee.fork( | ||
require.resolve('typescript/bin/tsc'), | ||
[ '-p', path.resolve(__dirname, './fixtures/ts/tsconfig.json') ] | ||
) | ||
.debug() | ||
.expect('code', 0) | ||
.end(); | ||
|
||
await coffee.fork(path.resolve(__dirname, './fixtures/ts/index.js')) | ||
// .debug() | ||
.expect('code', 0) | ||
.end(); | ||
}); | ||
}); |