From 96f20e3b2f4c3d21632c457a44aeeab93e77623f Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 25 Jul 2024 16:51:39 +0800 Subject: [PATCH] fix: improve code --- .../src/__tests__/sync-message-manager.test.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/server/src/__tests__/sync-message-manager.test.ts b/packages/core/server/src/__tests__/sync-message-manager.test.ts index b26db4c324..c3fd9f8af3 100644 --- a/packages/core/server/src/__tests__/sync-message-manager.test.ts +++ b/packages/core/server/src/__tests__/sync-message-manager.test.ts @@ -9,6 +9,7 @@ import { Plugin } from '@nocobase/server'; import { createMultiMockServer } from '@nocobase/test'; +import { uid } from '@nocobase/utils'; describe('sync-message-manager', () => { test('subscribe + publish', async () => { @@ -34,12 +35,18 @@ describe('sync-message-manager', () => { mockListener(message); } } - const [node1, node2] = await createMultiMockServer({ basename: 'base1', plugins: [MyPlugin] }); - await node1.pm.get(MyPlugin).sendSyncMessage('message1'); + const [app1, app2] = await createMultiMockServer({ + basename: uid(), + number: 2, // 创建几个 app 实例 + plugins: [MyPlugin], + }); + await app1.pm.get(MyPlugin).sendSyncMessage('message1'); expect(mockListener).toBeCalledTimes(1); expect(mockListener).toHaveBeenCalledWith('message1'); - await node2.pm.get(MyPlugin).sendSyncMessage('message2'); + await app2.pm.get(MyPlugin).sendSyncMessage('message2'); expect(mockListener).toBeCalledTimes(2); expect(mockListener).toHaveBeenCalledWith('message2'); + await app1.destroy(); + await app2.destroy(); }); });