Skip to content

Commit bb1ba0a

Browse files
authored
feat: --trace-warnings (#53)
* feat: start ensure no stderr, so open --trace-warnings will helpful for debug * test: ci16 * chore: github action * test: fix testcase * test: add --no-deprecation effect test * fix: testcase * fix: testcase
1 parent cb00441 commit bb1ba0a

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

.github/workflows/nodejs.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches:
9+
- master
910
pull_request:
10-
branches: [ master ]
11+
branches:
12+
- master
1113
schedule:
1214
- cron: '0 2 * * *'
1315

@@ -18,7 +20,7 @@ jobs:
1820
strategy:
1921
fail-fast: false
2022
matrix:
21-
node-version: [12, 14]
23+
node-version: [12, 14, 16]
2224
os: [ubuntu-latest, windows-latest, macos-latest]
2325

2426
steps:

lib/cmd/start.js

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class StartCommand extends Command {
131131

132132
// additional execArgv
133133
execArgvObj.deprecation = false; // --no-deprecation
134+
execArgvObj.traceWarnings = true; // --trace-warnings
134135

135136
const command = argv.node || 'node';
136137

test/fixtures/trace-warnings/app.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
const Event = require('events');
4+
const event = new Event();
5+
event.setMaxListeners(1);
6+
7+
module.exports = () => {
8+
// --trace-warnings test about MaxListenersExceededWarning
9+
event.on('xx', () => {});
10+
event.on('xx', () => {});
11+
12+
// will not effect --no-deprecation argv
13+
new Buffer('aaa');
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "trace-warnings",
3+
"version": "1.0.0"
4+
}

test/start.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ describe('test/start.test.js', () => {
123123
assert(result.data.toString() === 'hi, egg');
124124
});
125125

126+
it('should start --trace-warnings work', function* () {
127+
app = coffee.fork(eggBin, [ 'start', '--workers=1', path.join(__dirname, 'fixtures/trace-warnings') ]);
128+
app.debug();
129+
app.expect('code', 0);
130+
131+
yield sleep(waitTime);
132+
133+
assert(app.stderr.includes('MaxListenersExceededWarning:'));
134+
assert(app.stderr.includes('app.js:10:9')); // should had trace
135+
assert(!app.stdout.includes('DeprecationWarning:'));
136+
});
137+
126138
it.skip('should get ready', function* () {
127139
app = coffee.fork(path.join(__dirname, './fixtures/ipc-bin/start.js'), [], {
128140
env: {

test/stop.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('test/stop.test.js', () => {
6464

6565
// no way to handle the SIGTERM signal in windows ?
6666
if (!isWin) {
67-
assert(app.stdout.includes('[master] receive signal SIGTERM, closing'));
67+
assert(app.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
6868
assert(app.stdout.includes('[master] exit with code:0'));
6969
assert(app.stdout.includes('[app_worker] exit with code:0'));
7070
// assert(app.stdout.includes('[agent_worker] exit with code:0'));
@@ -106,7 +106,7 @@ describe('test/stop.test.js', () => {
106106

107107
// no way to handle the SIGTERM signal in windows ?
108108
if (!isWin) {
109-
assert(stdout.includes('[master] receive signal SIGTERM, closing'));
109+
assert(stdout.includes('[master] master is killed by signal SIGTERM, closing'));
110110
assert(stdout.includes('[master] exit with code:0'));
111111
assert(stdout.includes('[app_worker] exit with code:0'));
112112
}
@@ -191,7 +191,7 @@ describe('test/stop.test.js', () => {
191191

192192
// no way to handle the SIGTERM signal in windows ?
193193
if (!isWin) {
194-
assert(app.stdout.includes('[master] receive signal SIGTERM, closing'));
194+
assert(app.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
195195
assert(app.stdout.includes('[master] exit with code:0'));
196196
assert(app.stdout.includes('[app_worker] exit with code:0'));
197197
// assert(app.stdout.includes('[agent_worker] exit with code:0'));
@@ -248,7 +248,7 @@ describe('test/stop.test.js', () => {
248248

249249
// no way to handle the SIGTERM signal in windows ?
250250
if (!isWin) {
251-
assert(app.stdout.includes('[master] receive signal SIGTERM, closing'));
251+
assert(app.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
252252
assert(app.stdout.includes('[master] exit with code:0'));
253253
assert(app.stdout.includes('[app_worker] exit with code:0'));
254254
// assert(app.stdout.includes('[agent_worker] exit with code:0'));
@@ -261,7 +261,7 @@ describe('test/stop.test.js', () => {
261261

262262
// no way to handle the SIGTERM signal in windows ?
263263
if (!isWin) {
264-
assert(app2.stdout.includes('[master] receive signal SIGTERM, closing'));
264+
assert(app2.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
265265
assert(app2.stdout.includes('[master] exit with code:0'));
266266
assert(app2.stdout.includes('[app_worker] exit with code:0'));
267267
}
@@ -275,7 +275,7 @@ describe('test/stop.test.js', () => {
275275
beforeEach(function* () {
276276
yield utils.cleanup(timeoutPath);
277277
app = coffee.fork(eggBin, [ 'start', '--workers=2', '--title=stop-timeout', timeoutPath ]);
278-
// app.debug();
278+
app.debug();
279279
app.expect('code', 0);
280280

281281
yield sleep(waitTime);
@@ -304,7 +304,7 @@ describe('test/stop.test.js', () => {
304304

305305
// no way to handle the SIGTERM signal in windows ?
306306
if (!isWin) {
307-
assert(app.stdout.includes('[master] receive signal SIGTERM, closing'));
307+
assert(app.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
308308
assert(app.stdout.match(/app_worker#\d+:\d+ disconnect/));
309309
assert(app.stdout.match(/don't fork, because worker:\d+ will be kill soon/));
310310
}
@@ -326,7 +326,7 @@ describe('test/stop.test.js', () => {
326326

327327
// no way to handle the SIGTERM signal in windows ?
328328
if (!isWin) {
329-
assert(app.stdout.includes('[master] receive signal SIGTERM, closing'));
329+
assert(app.stdout.includes('[master] master is killed by signal SIGTERM, closing'));
330330
assert(app.stdout.includes('[master] exit with code:0'));
331331
assert(app.stdout.includes('[agent_worker] exit with code:0'));
332332
}

0 commit comments

Comments
 (0)