Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Mar 10, 2025
1 parent 5b593bb commit c369e60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
18 changes: 1 addition & 17 deletions patch/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ function getRequestDetail(req, res, start, sent) {
return `${offset},${url},${req.method},${sent},${res.statusCode},${rt}`;
}

let _onHttpServerRequestStart;
function subscribeHttpServerRequestStart(options) {
if (_onHttpServerRequestStart) {
return;
}

const { setHttpConfig, addLiveRequest, addCloseRequest, addSentRequest,
addRequestTimeout, addHttpStatusCode, addHttpProfilingDetail, patch_http_timeout } = options;

Expand Down Expand Up @@ -57,17 +52,6 @@ function subscribeHttpServerRequestStart(options) {
// use diagnostics_channel
const diagnosticsChannel = require('diagnostics_channel');
diagnosticsChannel.subscribe('http.server.request.start', onHttpServerRequestStart);
_onHttpServerRequestStart = onHttpServerRequestStart;
}

function unsubscribeHttpServerRequestStart() {
if (!_onHttpServerRequestStart) {
return;
}

const diagnosticsChannel = require('diagnostics_channel');
diagnosticsChannel.unsubscribe('http.server.request.start', _onHttpServerRequestStart);
_onHttpServerRequestStart = null;
}

module.exports = { subscribeHttpServerRequestStart, unsubscribeHttpServerRequestStart };
module.exports = { subscribeHttpServerRequestStart };
8 changes: 2 additions & 6 deletions test/patch/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

const http = require('http');
const expect = require('expect.js');
const { subscribeHttpServerRequestStart, unsubscribeHttpServerRequestStart } = require('../../patch/http');
const { subscribeHttpServerRequestStart } = require('../../patch/http');

const status = {};

describe(`monitor http server request with diagnostics_channel`, function () {
describe.only(`monitor http server request with diagnostics_channel`, function () {
const requestTimes = 5;
let triggerTimes = 0;

Expand Down Expand Up @@ -63,10 +63,6 @@ describe(`monitor http server request with diagnostics_channel`, function () {
server.close();
});

after(function () {
unsubscribeHttpServerRequestStart();
});

it('http config.http_detail_profiling should be false', function () {
expect(httpConfig.http_detail_profiling).to.be(false);
});
Expand Down

0 comments on commit c369e60

Please sign in to comment.