Skip to content

Commit

Permalink
fix: should restore agent messenger first (#3658)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Apr 29, 2019
1 parent 99eb753 commit 04adcf9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Agent extends EggApplication {
methodName, stack);
originMethod.apply(this, arguments);
};
messenger.once('egg-ready', () => {
messenger.prependOnceListener('egg-ready', () => {
messenger[methodName] = originMethod;
});
}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/apps/boot-app/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = class extends BaseHookClass {
super(agent);
agent.bootLog = [];
assert(this.config);
agent.messenger.on('egg-ready', () => {
agent.messenger.sendToApp('agent2app');
});
}

configDidLoad() {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/apps/boot-app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = class extends BaseHookClass {
super(app);
app.bootLog = [];
assert(this.config);
app.messenger.on('agent2app', () => {
app.messengerLog = true;
});
}

configDidLoad() {
Expand Down
8 changes: 8 additions & 0 deletions test/lib/core/loader/load_boot.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const assert = require('assert');
const path = require('path');
const { fs } = require('mz');
const utils = require('../../../utils');

describe('test/lib/core/loader/load_boot.test.js', () => {
Expand All @@ -15,6 +17,12 @@ describe('test/lib/core/loader/load_boot.test.js', () => {
app.mockLog();
await app.close();
app.expectLog('app is ready');

// should restore
const logContent = await fs.readFile(path.join(app.config.logger.dir, 'egg-agent.log'), 'utf-8');
assert(!logContent.includes('agent can\'t call sendToApp before server started'));
assert(app.messengerLog);

assert.deepStrictEqual(app.bootLog, [ 'configDidLoad',
'didLoad',
'willReady',
Expand Down

0 comments on commit 04adcf9

Please sign in to comment.