-
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.
fix: there is no uv_handle_type_name in earlier versions of libuv
PR-URL: https://github.com/hyj1991/xprofiler/pull/45 Reviewed-By: hyj1991 <yeekwanvong@gmail.com>
- Loading branch information
Showing
9 changed files
with
141 additions
and
29 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
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
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
const http = require('http'); | ||
const EventEmitter = require('events').EventEmitter; | ||
const mm = require('mm'); | ||
const expect = require('expect.js'); | ||
const { patchHttp } = require('../../patch/http'); | ||
|
||
|
||
describe(`patch http.createServer(cb)`, function () { | ||
const requestTimes = 5; | ||
let triggerTimes = 0; | ||
|
||
let liveRequest = 0; | ||
let closeRequest = 0; | ||
let sentRequest = 0; | ||
|
||
function addLiveRequest() { | ||
liveRequest++; | ||
} | ||
|
||
function addCloseRequest() { | ||
closeRequest++; | ||
} | ||
|
||
function addSentRequest() { | ||
sentRequest++; | ||
} | ||
|
||
function mockCreateServer(opts, requestHandle) { | ||
return new Promise(resolve => { | ||
let times = 0; | ||
const interval = setInterval(() => { | ||
if (times < requestTimes) { | ||
const request = new EventEmitter(); | ||
const response = new EventEmitter(); | ||
if (typeof opts === 'function') { | ||
opts(request, response); | ||
} else if (typeof requestHandle === 'function') { | ||
requestHandle(request, response); | ||
} | ||
times++; | ||
} else { | ||
clearInterval(interval); | ||
resolve(); | ||
} | ||
}, 100); | ||
}); | ||
} | ||
|
||
before(async function () { | ||
mm(http, 'createServer', mockCreateServer); | ||
patchHttp(addLiveRequest, addCloseRequest, addSentRequest); | ||
await http.createServer(function (request, response) { | ||
triggerTimes++; | ||
response.emit('finish'); | ||
response.emit('close'); | ||
}); | ||
|
||
await http.createServer({}, function (request, response) { | ||
triggerTimes++; | ||
response.emit('finish'); | ||
response.emit('close'); | ||
}); | ||
|
||
await http.createServer({}, {}, function (request, response) { | ||
triggerTimes++; | ||
response.emit('finish'); | ||
response.emit('close'); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
mm.restore(); | ||
}); | ||
|
||
it('patch should be ok', function () { | ||
expect(http.createServer).not.to.be(mockCreateServer); | ||
}); | ||
|
||
it(`request handler should trigger ${requestTimes} * 2 times`, function () { | ||
expect(triggerTimes).to.be(requestTimes * 2); | ||
}); | ||
|
||
it(`live request shoule be ${requestTimes} * 2`, function () { | ||
expect(liveRequest).to.be(requestTimes * 2); | ||
}); | ||
|
||
it(`close request shoule be ${requestTimes} * 2`, function () { | ||
expect(closeRequest).to.be(requestTimes * 2); | ||
}); | ||
|
||
it(`sent request shoule be ${requestTimes} * 2`, function () { | ||
expect(sentRequest).to.be(requestTimes * 2); | ||
}); | ||
}); |
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