Skip to content

Add cloning to MultiplayerPlaylistItem, and tests using fake data #32372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 3, 2025

Conversation

smoogipoo
Copy link
Contributor

@smoogipoo smoogipoo commented Mar 14, 2025

This is intended to fix a separate issue I've found server-side, where MultiplayerPlaylistItem's are cloned manually: https://github.com/ppy/osu-server-spectator/blob/8c3c87039659d623870f77bf7bf3d1610f202f85/osu.Server.Spectator/Hubs/Multiplayer/MultiplayerQueue.cs#L254-L263
Given that this has come up a few times now, I think it's best to add cloning and supporting tests.

For testing, I've added the Bogus library. It seems well supported and MIT. Its strict mode tells us when a property isn't being touched by the test, which should catch any missed updates to these methods.

The checksum change is irrelevant to the above fix - it was noticed separately as a consequence of the tests.

@bdach bdach self-requested a review March 17, 2025 09:09
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\osu.TestProject.props" />
<ItemGroup Label="Package References">
<PackageReference Include="Bogus" Version="35.6.2" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably gonna need @peppy's ok for the inclusion on this. It seems mostly legit on a quick look although there's some DRM-shaped stuff happening because the library has paid extensions included, and also some other somewhat dodgy stuff.

Copy link
Contributor Author

@smoogipoo smoogipoo Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One alternative that just came to my mind, is I can replace it with

public MultiplayerPlaylistItem Clone()
{
    MultiplayerPlaylistItem clone = (MultiplayerPlaylistItem)MemberwiseClone();
    clone.RequiredMods = RequiredMods.ToArray();
    clone.AllowedMods = AllowedMods.ToArray();
    return clone;
}

And we can live without tests under the premise that MemberwiseClone() has been properly tested by .NET itself. Thoughts?

Copy link
Contributor Author

@smoogipoo smoogipoo Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but the tests also test MPI -> PI -> MPI... Think I'll replace with MemberwiseClone() in any case. :/

I hope these classes can be interfaced or merged, at some point...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay since it's limited to the tests project.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Mar 18, 2025
bdach
bdach previously approved these changes Mar 20, 2025
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no major objections I guess, requesting @peppy review for the new library inclusion

@bdach bdach requested a review from peppy March 20, 2025 07:35
@peppy peppy merged commit ac88220 into ppy:master Apr 3, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants