Skip to content

Commit b05d6d4

Browse files
committed
feat: add ipc channel in nonDaemon mode
1 parent 262ef4c commit b05d6d4

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

lib/cmd/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class StartCommand extends Command {
163163
// check start status
164164
yield this.checkStatus(argv);
165165
} else {
166-
options.stdio = options.stdio || 'inherit';
166+
options.stdio = [ 'inherit', 'inherit', 'inherit', 'ipc' ];
167167
debug('Run spawn `node %s`', eggArgs.join(' '));
168168
const child = this.child = spawn('node', eggArgs, options);
169169
child.once('exit', code => {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"autod": "^3.0.1",
24+
"co": "^4.6.0",
2425
"coffee": "^4.1.0",
2526
"egg": "^1.11.0",
2627
"egg-bin": "^4.3.5",

test/fixtures/ipc-bin/start.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const co = require('co');
4+
5+
const BaseStartCommand = require('../../../lib/cmd/start');
6+
7+
class StartCommand extends BaseStartCommand {
8+
* run(context) {
9+
yield super.run(context);
10+
const child = this.child;
11+
child.on('message', msg => {
12+
if (msg && msg.action === 'egg-ready') {
13+
console.log('READY!!!');
14+
this.exit(0);
15+
}
16+
});
17+
}
18+
}
19+
20+
const start = new StartCommand();
21+
22+
co(function* () {
23+
yield start.run({
24+
argv: {
25+
framework: 'custom-framework',
26+
_: [ process.env.BASE_DIR ],
27+
workers: 2,
28+
title: 'egg-server-example',
29+
},
30+
cwd: process.env.BASE_DIR,
31+
execArgv: [],
32+
env: {
33+
PATH: process.env.PATH,
34+
},
35+
});
36+
});
37+

test/start.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ describe('test/start.test.js', () => {
5656
assert(!app.stdout.includes('app_worker#3:'));
5757
const result = yield httpclient.request('http://127.0.0.1:7001');
5858
assert(result.data.toString() === 'hi, egg');
59+
app.proc.kill();
60+
});
61+
62+
it('should get ready', function* () {
63+
app = coffee.fork(path.join(__dirname, './fixtures/ipc-bin/start.js'), [], {
64+
env: {
65+
BASE_DIR: fixturePath,
66+
PATH: process.env.PATH,
67+
},
68+
});
69+
// app.debug();
70+
app.expect('code', 0);
71+
72+
yield sleep(waitTime);
73+
74+
assert(app.stderr === '');
75+
assert(app.stdout.includes('READY!!!'));
76+
assert(app.stdout.includes('--title=egg-server-example'));
77+
assert(app.stdout.includes('"title":"egg-server-example"'));
78+
assert(app.stdout.match(/custom-framework started on http:\/\/127\.0\.0\.1:7001/));
79+
assert(app.stdout.includes('app_worker#2:'));
80+
assert(!app.stdout.includes('app_worker#3:'));
5981
});
6082
});
6183

0 commit comments

Comments
 (0)