kt-template-online-api/test/modules/qqbot/plugin-platform/plugin-registry-timeout.spec.ts

37 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { QqbotPluginRegistryService } from '../../../../src/modules/qqbot/plugin-platform/application/registry/qqbot-plugin-registry.service';
describe('QQBot plugin registry operation timeout', () => {
it('enforces manifest operation timeout for explicitly registered command plugins', async () => {
const commandRegistry = new QqbotPluginRegistryService();
commandRegistry.register({
key: 'demo-plugin',
name: 'Demo Plugin',
operations: [
{
execute: jest.fn(
() => new Promise((resolve) => setTimeout(resolve, 1000)),
),
key: 'demo.slow',
name: 'slow',
timeoutMs: 5,
},
],
version: '0.1.0',
});
await commandRegistry.onModuleInit();
await expect(
Promise.race([
commandRegistry.execute('demo-plugin', 'demo.slow', {}, {}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('test timeout waiting')), 50),
),
]),
).rejects.toMatchObject({
response: expect.objectContaining({
msg: 'QQBot 插件能力执行超时demo.slow',
}),
});
});
});