Skip to content

Commit

Permalink
core/room: transition immediately to released if room is initialized
Browse files Browse the repository at this point in the history
If room is in the initialized state, we can skip the detach process and skip straight to release.

Resolves #398
  • Loading branch information
AndyTWF committed Nov 14, 2024
1 parent 0e1b523 commit 851c801
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/room-lifecycle-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions test/core/room-lifecycle-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,23 @@ describe('room lifecycle manager', () => {
await waitForRoomLifecycleStatus(status, RoomStatus.Released);
});

it<TestContext>('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<TestContext>('resolves to released if existing attempt completes', (context) =>
new Promise<void>((resolve, reject) => {
vi.useFakeTimers();
Expand Down

0 comments on commit 851c801

Please sign in to comment.