Skip to content
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

Display up-to-date online status in user panels #31524

Merged
merged 17 commits into from
Feb 5, 2025
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
52 changes: 52 additions & 0 deletions osu.Game.Tests/Online/TestSceneMetadataClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Tests.Visual;
using osu.Game.Tests.Visual.Metadata;

namespace osu.Game.Tests.Online
{
[TestFixture]
[HeadlessTest]
public partial class TestSceneMetadataClient : OsuTestScene
{
private TestMetadataClient client = null!;

[SetUp]
public void Setup() => Schedule(() =>
{
Child = client = new TestMetadataClient();
});

[Test]
public void TestWatchingMultipleTimesInvokesServerMethodsOnce()
{
int countBegin = 0;
int countEnd = 0;

IDisposable token1 = null!;
IDisposable token2 = null!;

AddStep("setup", () =>
{
client.OnBeginWatchingUserPresence += () => countBegin++;
client.OnEndWatchingUserPresence += () => countEnd++;
});

AddStep("begin watching presence (1)", () => token1 = client.BeginWatchingUserPresence());
AddAssert("server method invoked once", () => countBegin, () => Is.EqualTo(1));

AddStep("begin watching presence (2)", () => token2 = client.BeginWatchingUserPresence());
AddAssert("server method not invoked a second time", () => countBegin, () => Is.EqualTo(1));

AddStep("end watching presence (1)", () => token1.Dispose());
AddAssert("server method not invoked", () => countEnd, () => Is.EqualTo(0));

AddStep("end watching presence (2)", () => token2.Dispose());
AddAssert("server method invoked once", () => countEnd, () => Is.EqualTo(1));
}
}
}
12 changes: 8 additions & 4 deletions osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public void SetUpSteps()
[Test]
public void TestBasicDisplay()
{
AddStep("Begin watching user presence", () => metadataClient.BeginWatchingUserPresence());
IDisposable token = null!;

AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence());
AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.ChoosingBeatmap() }));
AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType<UserGridPanel>().FirstOrDefault()?.User.Id == 2);
AddAssert("Spectate button disabled", () => currentlyOnline.ChildrenOfType<PurpleRoundedButton>().First().Enabled.Value, () => Is.False);
Expand All @@ -78,22 +80,24 @@ public void TestBasicDisplay()

AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null));
AddUntilStep("Panel no longer present", () => !currentlyOnline.ChildrenOfType<UserGridPanel>().Any());
AddStep("End watching user presence", () => metadataClient.EndWatchingUserPresence());
AddStep("End watching user presence", () => token.Dispose());
}

[Test]
public void TestUserWasPlayingBeforeWatchingUserPresence()
{
IDisposable token = null!;

AddStep("User began playing", () => spectatorClient.SendStartPlay(streamingUser.Id, 0));
AddStep("Begin watching user presence", () => metadataClient.BeginWatchingUserPresence());
AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence());
AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.ChoosingBeatmap() }));
AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType<UserGridPanel>().FirstOrDefault()?.User.Id == 2);
AddAssert("Spectate button enabled", () => currentlyOnline.ChildrenOfType<PurpleRoundedButton>().First().Enabled.Value, () => Is.True);

AddStep("User finished playing", () => spectatorClient.SendEndPlay(streamingUser.Id));
AddAssert("Spectate button disabled", () => currentlyOnline.ChildrenOfType<PurpleRoundedButton>().First().Enabled.Value, () => Is.False);
AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null));
AddStep("End watching user presence", () => metadataClient.EndWatchingUserPresence());
AddStep("End watching user presence", () => token.Dispose());
}

internal partial class TestUserLookupCache : UserLookupCache
Expand Down
Loading
Loading