Skip to content

Commit

Permalink
Merge pull request #400 from ably/room-lifecycle-release-on-initialized
Browse files Browse the repository at this point in the history
core/room: transition immediately to released if room is initialized
  • Loading branch information
AndyTWF authored Nov 14, 2024
2 parents 0e1b523 + 851c801 commit d222e0b
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 d222e0b

Please sign in to comment.