Skip to content

Commit

Permalink
Fix tests not working due to missing database
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Dec 16, 2020
1 parent 49d3be8 commit bf1a86c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
4 changes: 4 additions & 0 deletions osu.Server.Spectator.Tests/MultiplayerFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ public TestMultiplayerHub(MemoryDistributedCache cache)
{
}

protected override Task UpdateDatabaseParticipants(MultiplayerRoom room) => Task.CompletedTask;
protected override Task UpdateDatabaseSettings(MultiplayerRoom room) => Task.CompletedTask;
protected override Task EndDatabaseMatch(MultiplayerRoom room) => Task.CompletedTask;

protected override Task<MultiplayerRoom> RetrieveRoom(long roomId)
{
// bypass database for testing.
Expand Down
54 changes: 32 additions & 22 deletions osu.Server.Spectator/Hubs/MultiplayerHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task<MultiplayerRoom> JoinRoom(long roomId)
await Clients.Group(GetGroupId(roomId)).UserJoined(roomUser);
await Groups.AddToGroupAsync(Context.ConnectionId, GetGroupId(roomId));

await updateDatabaseParticipants(room);
await UpdateDatabaseParticipants(room);
}

await UpdateLocalUserState(new MultiplayerClientState(roomId));
Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task LeaveRoom()

room.Users.Remove(user);

await updateDatabaseParticipants(room);
await UpdateDatabaseParticipants(room);

if (room.Users.Count == 0)
{
Expand All @@ -160,13 +160,7 @@ public async Task LeaveRoom()
active_rooms.Remove(room.RoomID);
}

using (var conn = Database.GetConnection())
{
await conn.ExecuteAsync("UPDATE multiplayer_rooms SET ends_at = NOW() WHERE id = @RoomID", new
{
RoomID = room.RoomID
});
}
await EndDatabaseMatch(room);

return;
}
Expand Down Expand Up @@ -283,18 +277,7 @@ public async Task ChangeSettings(MultiplayerRoomSettings settings)

room.Settings = settings;

using (var conn = Database.GetConnection())
{
var dbPlaylistItem = new multiplayer_playlist_item(room);

await conn.ExecuteAsync("UPDATE multiplayer_rooms SET name = @Name WHERE id = @RoomID", new
{
RoomID = room.RoomID,
Name = room.Settings.Name
});

await conn.ExecuteAsync("UPDATE multiplayer_playlist_items SET beatmap_id = @beatmap_id, ruleset_id = @ruleset_id, required_mods = @required_mods, updated_at = NOW() WHERE room_id = @room_id", dbPlaylistItem);
}
await UpdateDatabaseSettings(room);

await Clients.Group(GetGroupId(room.RoomID)).SettingsChanged(settings);
}
Expand All @@ -315,7 +298,34 @@ protected override Task OnDisconnectedAsync(Exception exception, MultiplayerClie
/// <param name="gameplay">Whether the group ID should be for active gameplay, or room control messages.</param>
public static string GetGroupId(long roomId, bool gameplay = false) => $"room:{roomId}:{gameplay}";

private async Task updateDatabaseParticipants(MultiplayerRoom room)
protected virtual async Task UpdateDatabaseSettings(MultiplayerRoom room)
{
using (var conn = Database.GetConnection())
{
var dbPlaylistItem = new multiplayer_playlist_item(room);

await conn.ExecuteAsync("UPDATE multiplayer_rooms SET name = @Name WHERE id = @RoomID", new
{
RoomID = room.RoomID,
Name = room.Settings.Name
});

await conn.ExecuteAsync("UPDATE multiplayer_playlist_items SET beatmap_id = @beatmap_id, ruleset_id = @ruleset_id, required_mods = @required_mods, updated_at = NOW() WHERE room_id = @room_id", dbPlaylistItem);
}
}

protected virtual async Task EndDatabaseMatch(MultiplayerRoom room)
{
using (var conn = Database.GetConnection())
{
await conn.ExecuteAsync("UPDATE multiplayer_rooms SET ends_at = NOW() WHERE id = @RoomID", new
{
RoomID = room.RoomID
});
}
}

protected virtual async Task UpdateDatabaseParticipants(MultiplayerRoom room)
{
using (var conn = Database.GetConnection())
{
Expand Down

0 comments on commit bf1a86c

Please sign in to comment.