fix(core): close Bridges on exit without a fake offline
This commit is contained in:
9 files changed
+92
-8
No files matched your search
@@ -382,6 +382,7 @@ export class OneBotManager {
|
||||
}
|
||||
|
||||
private onSessionClosed(uin: string): void {
|
||||
if (this.disposed) return;
|
||||
const migration = this.databaseMigrations.get(uin);
|
||||
if (migration) {
|
||||
migration.cancelled = true;
|
||||
|
||||
@@ -513,4 +513,28 @@ describe('OneBotManager lifecycle failure accounting', () => {
|
||||
|
||||
await expect(manager.dispose()).rejects.toThrow(/failed to dispose OneBot manager cleanly/);
|
||||
});
|
||||
|
||||
it('ignores session-closed after dispose so process-exit closed does not retire again', async () => {
|
||||
const manager = new OneBotManager();
|
||||
const dispose = vi.fn(async () => ({ closed: true, errors: [] }));
|
||||
const instance = fakeInstance('10001', dispose);
|
||||
const internals = manager as unknown as {
|
||||
instances: Map<string, OneBotInstance>;
|
||||
retiringInstances: Set<OneBotInstance>;
|
||||
onSessionClosed(uin: string): void;
|
||||
};
|
||||
internals.instances.set('10001', instance);
|
||||
|
||||
await manager.dispose();
|
||||
expect(dispose).toHaveBeenCalledOnce();
|
||||
|
||||
const lateDispose = vi.fn(async () => ({ closed: true, errors: [] }));
|
||||
const late = fakeInstance('10001', lateDispose);
|
||||
internals.instances.set('10001', late);
|
||||
internals.onSessionClosed('10001');
|
||||
|
||||
expect(lateDispose).not.toHaveBeenCalled();
|
||||
expect(internals.retiringInstances.has(late)).toBe(false);
|
||||
expect(manager.getInstance('10001')).toBe(late);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user