Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,31 @@ public async Task CanNotInvitePlayersToRoom()
await Assert.ThrowsAsync<InvalidStateException>(() => Hub.InvitePlayer(USER_ID_2));
}

/// <summary>
/// Tests that the stage advances when users leave, particularly in the case where the server is waiting on one to download the beatmap.
/// </summary>
[Fact]
public async Task StageAdvancesWhenUsersLeaveDuringDownload()
{
await Hub.JoinRoom(ROOM_ID);

SetUserContext(ContextUser2);
await Hub.JoinRoom(ROOM_ID);

await gotoStage(MatchmakingStage.WaitingForClientsBeatmapDownload);

// Ready up the first user.
SetUserContext(ContextUser);
await Hub.ChangeState(MultiplayerUserState.Ready);
await Hub.ChangeBeatmapAvailability(BeatmapAvailability.LocallyAvailable());

// Quit the second user.
SetUserContext(ContextUser2);
await Hub.LeaveRoom();

await verifyStage(MatchmakingStage.GameplayWarmupTime);
}

private async Task verifyStage(MatchmakingStage stage)
{
using (var room = await Rooms.GetForUse(ROOM_ID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ public async Task HandleUserJoined(MultiplayerRoomUser user)
}
}

public Task HandleUserLeft(MultiplayerRoomUser user)
public async Task HandleUserLeft(MultiplayerRoomUser user)
{
return Task.CompletedTask;
await updateStageFromUserStateChange();
}

public Task AddPlaylistItem(MultiplayerPlaylistItem item, MultiplayerRoomUser user)
Expand All @@ -176,13 +176,7 @@ public Task RemovePlaylistItem(long playlistItemId, MultiplayerRoomUser user)

public async Task HandleUserStateChanged(MultiplayerRoomUser user)
{
switch (state.Stage)
{
case MatchmakingStage.WaitingForClientsBeatmapDownload:
if (allUsersReady())
await stageGameplayWarmupTime(room);
break;
}
await updateStageFromUserStateChange();
}

public void SkipToNextStage(out Task countdownTask)
Expand Down Expand Up @@ -367,6 +361,17 @@ await room.StartCountdown(new MatchmakingStageCountdown
}, continuation);
}

private async Task updateStageFromUserStateChange()
{
switch (state.Stage)
{
case MatchmakingStage.WaitingForClientsBeatmapDownload:
if (allUsersReady())
await stageGameplayWarmupTime(room);
break;
}
}

private bool allUsersReady()
{
return room.Users.All(u => u.State == MultiplayerUserState.Ready);
Expand Down
Loading