From 851c80120dca494535f80269b6d83b0fda9c9d41 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 14 Nov 2024 10:08:36 +0000 Subject: [PATCH] core/room: transition immediately to released if room is initialized If room is in the initialized state, we can skip the detach process and skip straight to release. Resolves #398 --- src/core/room-lifecycle-manager.ts | 4 ++-- test/core/room-lifecycle-manager.test.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/room-lifecycle-manager.ts b/src/core/room-lifecycle-manager.ts index 29c04753..c6d518eb 100644 --- a/src/core/room-lifecycle-manager.ts +++ b/src/core/room-lifecycle-manager.ts @@ -789,8 +789,8 @@ export class RoomLifecycleManager { return; } - // If we're already detached, then we can transition to released immediately - if (this._lifecycle.status === RoomStatus.Detached) { + // If we're already detached, or we never attached in the first place, then we can transition to released immediately + if (this._lifecycle.status === RoomStatus.Detached || this._lifecycle.status === RoomStatus.Initialized) { this._lifecycle.setStatus({ status: RoomStatus.Released }); return; } diff --git a/test/core/room-lifecycle-manager.test.ts b/test/core/room-lifecycle-manager.test.ts index 1389b340..6b83d56b 100644 --- a/test/core/room-lifecycle-manager.test.ts +++ b/test/core/room-lifecycle-manager.test.ts @@ -2510,6 +2510,23 @@ describe('room lifecycle manager', () => { await waitForRoomLifecycleStatus(status, RoomStatus.Released); }); + it('resolves immediately and transitions to released if the room is initialized', async (context) => { + const status = new DefaultRoomLifecycle('roomId', makeTestLogger()); + context.firstContributor.emulateStateChange({ + current: AblyChannelState.Detached, + previous: 'initialized', + resumed: false, + reason: baseError, + }); + status.setStatus({ status: RoomStatus.Initialized }); + + const monitor = new RoomLifecycleManager(status, [context.firstContributor], makeTestLogger(), 5); + + await expect(monitor.release()).resolves.toBeUndefined(); + + await waitForRoomLifecycleStatus(status, RoomStatus.Released); + }); + it('resolves to released if existing attempt completes', (context) => new Promise((resolve, reject) => { vi.useFakeTimers();