Skip to content

Commit

Permalink
fix: beginModuleScope should be reentrant (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu authored Jan 29, 2023
1 parent 4e5f026 commit 648aeaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugin/tegg/lib/ctx_lifecycle_middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { TEggPluginContext } from '../app/extend/context';
import { EggContextImpl } from './EggContextImpl';
import { ROOT_PROTO } from '@eggjs/egg-module-common';
import { ROOT_PROTO, TEGG_CONTEXT } from '@eggjs/egg-module-common';

export default async function ctxLifecycleMiddleware(ctx: TEggPluginContext, next) {
// should not recreate teggContext
if (ctx[TEGG_CONTEXT]) {
await next();
return;
}

const lifecycle = {};

const teggCtx = new EggContextImpl(ctx);
Expand Down
11 changes: 11 additions & 0 deletions plugin/tegg/test/app/extend/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,15 @@ describe('test/app/extend/context.test.ts', () => {
});
});
});

describe('beginModuleScope', () => {
it('should be reentrant', async () => {
await app.mockModuleContextScope(async ctx => {
await ctx.beginModuleScope(async () => {
// ...do nothing
});
assert(ctx.teggContext.destroyed === false);
});
});
});
});

0 comments on commit 648aeaf

Please sign in to comment.