fix: test error

This commit is contained in:
chenos 2024-08-01 08:07:38 +08:00 committed by mytharcher
parent 288823dab1
commit b927115230
3 changed files with 25 additions and 19 deletions

View File

@ -239,13 +239,15 @@ export function mockServer(options: ApplicationOptions = {}) {
...options,
});
const basename = app.options.pubSubManager?.channelPrefix || app.name;
const basename = app.options.pubSubManager?.channelPrefix;
app.pubSubManager.setAdapter(
MemoryPubSubAdapter.create(basename, {
debounce: 500,
}),
);
if (basename) {
app.pubSubManager.setAdapter(
MemoryPubSubAdapter.create(basename, {
debounce: 500,
}),
);
}
return app;
}

View File

@ -16,7 +16,7 @@ describe('file-manager > cluster', () => {
beforeEach(async () => {
cluster = await createMockCluster({
plugins: [[Plugin, { name: 'file-manager' }]],
plugins: ['file-manager'],
});
});
@ -44,9 +44,7 @@ describe('file-manager > cluster', () => {
path: 'a',
});
expect(p1.storagesCache.get(s1.id).path).toEqual('a');
await sleep(550);
expect(p2.storagesCache.get(s1.id).path).toEqual('a');
});
});

View File

@ -190,19 +190,25 @@ export default class PluginFileManagerServer extends Plugin {
});
const Storage = this.db.getModel('storages');
Storage.afterSave((m) => {
Storage.afterSave((m, { transaction }) => {
this.storagesCache.set(m.id, m.toJSON());
this.sendSyncMessage({
type: 'storageChange',
storageId: m.id,
});
this.sendSyncMessage(
{
type: 'storageChange',
storageId: m.id,
},
{ transaction },
);
});
Storage.afterDestroy((m) => {
Storage.afterDestroy((m, { transaction }) => {
this.storagesCache.delete(m.id);
this.sendSyncMessage({
type: 'storageRemove',
storageId: m.id,
});
this.sendSyncMessage(
{
type: 'storageRemove',
storageId: m.id,
},
{ transaction },
);
});
this.app.acl.registerSnippet({