Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure app ready on parallel mode #155

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/app_handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const debug = require('util').debuglog('egg-mock:bootstrap');
const debug = require('util').debuglog('egg-mock:bootstrap:app_handler');
const mockParallelApp = require('./parallel/app');
const { setupAgent } = require('./agent_handler');
const mock = require('../index').default;
Expand All @@ -8,10 +8,10 @@ let app;

exports.setupApp = () => {
if (app) {
debug('return exists app');
return app;
}


const options = getEggOptions();
debug('env.ENABLE_MOCHA_PARALLEL: %s, process.env.AUTO_AGENT: %s',
process.env.ENABLE_MOCHA_PARALLEL, process.env.AUTO_AGENT);
Expand Down Expand Up @@ -47,6 +47,9 @@ exports.getApp = async suite => {
if (getAppCallback) {
return getAppCallback(suite);
}
if (app) {
await app.ready();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是哪里用的时候没有 await ready?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runSuite 里面 await 了这个 proxy app,会直接卡住 https://github.com/eggjs/egg-mock/blob/master/lib/inject_context.js#L22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该会走到 get then 返回 undefined。会卡住能重现吗?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以的,egg-bin 里面那个并行测试用例必现。

}
return app;
};

Expand Down
4 changes: 3 additions & 1 deletion lib/inject_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function injectContext(mocha) {

// Inject ctx for before/after.
Runner.prototype.runSuite = async function(suite, fn) {
debug('run suite: %s %b', suite.title, !!(suite.ctx && suite[EGG_CONTEXT]));
debug('run suite: %j %s', suite.title, !!(suite.ctx && suite[EGG_CONTEXT]));
const app = await appHandler.getApp(suite);
debug('get app: %s', !!app);
const self = this;
if (!app) {
return runSuite.call(self, suite, fn);
Expand Down Expand Up @@ -47,6 +48,7 @@ function injectContext(mocha) {
// Inject ctx for beforeEach/it/afterEach.
// And ctx with before/after is not same as beforeEach/it/afterEach.
Runner.prototype.runTests = async function(suite, fn) {
debug('run tests: %j %s', suite.title);
const app = await appHandler.getApp(suite);
const self = this;
if (!app) {
Expand Down
1 change: 0 additions & 1 deletion lib/parallel/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class MockAgent extends Base {
this[APP_INIT] = true;
debug('this[APP_INIT] = true');
this[BIND_EVENT]();
debug('http server instantiate');
await agent.ready();

const msg = {
Expand Down