1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Merge pull request #16165 from smoogipoo/fix-multiplayer-tests

Add better fix for intermittent multiplayer tests as a result of async room joins
This commit is contained in:
Dean Herbert 2021-12-20 13:44:29 +09:00 committed by GitHub
commit ce6503ff8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 34 deletions

View File

@ -41,7 +41,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
private TestMultiplayerScreenStack multiplayerScreenStack;
protected TestMultiplayerClient Client => multiplayerScreenStack.Client;
protected TestMultiplayerRoomManager RoomManager => multiplayerScreenStack.RoomManager;
[Cached(typeof(UserLookupCache))]
private UserLookupCache lookupCache = new TestUserLookupCache();
@ -93,7 +92,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for join", () => RoomManager.RoomJoined);
AddUntilStep("wait for join", () => Client.RoomJoined);
}
[Test]

View File

@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("Press select", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddUntilStep("wait for join", () => roomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
}
[Test]
@ -295,7 +295,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("join room", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddUntilStep("wait for join", () => roomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
AddAssert("Check participant count correct", () => client.APIRoom?.ParticipantCount.Value == 1);
AddAssert("Check participant list contains user", () => client.APIRoom?.RecentParticipants.Count(u => u.Id == API.LocalUser.Value.Id) == 1);
@ -353,7 +353,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddUntilStep("wait for join", () => roomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
}
[Test]
@ -646,7 +646,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddStep("join room", () => InputManager.Key(Key.Enter));
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
AddUntilStep("wait for join", () => roomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
AddAssert("local room has correct settings", () =>
{
@ -838,7 +838,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for join", () => roomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
}
}
}

View File

@ -187,7 +187,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for join", () => multiplayerScreenStack.RoomManager.RoomJoined);
AddUntilStep("wait for join", () => client.RoomJoined);
}
}
}

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
protected new MultiplayerTestSceneDependencies OnlinePlayDependencies => (MultiplayerTestSceneDependencies)base.OnlinePlayDependencies;
public bool RoomJoined => RoomManager.RoomJoined;
public bool RoomJoined => Client.RoomJoined;
private readonly bool joinRoom;

View File

@ -31,9 +31,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
private readonly Bindable<bool> isConnected = new Bindable<bool>(true);
public new Room? APIRoom => base.APIRoom;
public Action<MultiplayerRoom>? RoomSetupAction;
public bool RoomJoined { get; private set; }
[Resolved]
private IAPIProvider api { get; set; } = null!;
@ -49,7 +50,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
private MultiplayerPlaylistItem? currentItem => Room?.Playlist[currentIndex];
private int currentIndex;
private long lastPlaylistItemId;
public TestMultiplayerClient(TestMultiplayerRoomManager roomManager)
@ -217,9 +217,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
// emulate the server sending this after the join room. scheduler required to make sure the join room event is fired first (in Join).
changeMatchType(Room.Settings.MatchType).Wait();
RoomJoined = true;
}
protected override Task LeaveRoomInternal() => Task.CompletedTask;
protected override Task LeaveRoomInternal()
{
RoomJoined = false;
return Task.CompletedTask;
}
public override Task TransferHost(int userId) => ((IMultiplayerClient)this).HostChanged(userId);

View File

@ -17,8 +17,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
/// </summary>
public class TestMultiplayerRoomManager : MultiplayerRoomManager
{
public bool RoomJoined { get; private set; }
private readonly TestRoomRequestsHandler requestsHandler;
public TestMultiplayerRoomManager(TestRoomRequestsHandler requestsHandler)
@ -29,28 +27,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
public IReadOnlyList<Room> ServerSideRooms => requestsHandler.ServerSideRooms;
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{
base.CreateRoom(room, r =>
{
onSuccess?.Invoke(r);
RoomJoined = true;
}, onError);
}
=> base.CreateRoom(room, r => onSuccess?.Invoke(r), onError);
public override void JoinRoom(Room room, string password = null, Action<Room> onSuccess = null, Action<string> onError = null)
{
base.JoinRoom(room, password, r =>
{
onSuccess?.Invoke(r);
RoomJoined = true;
}, onError);
}
public override void PartRoom()
{
base.PartRoom();
RoomJoined = false;
}
=> base.JoinRoom(room, password, r => onSuccess?.Invoke(r), onError);
/// <summary>
/// Adds a room to a local "server-side" list that's returned when a <see cref="GetRoomsRequest"/> is fired.