1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Fix intermittent multiplayer tests

This commit is contained in:
smoogipoo 2021-10-15 00:10:39 +09:00
parent 79d9aa7383
commit e6ee360511
2 changed files with 26 additions and 14 deletions

View File

@ -359,22 +359,25 @@ namespace osu.Game.Online.Multiplayer
if (Room == null)
return;
await PopulateUser(user).ConfigureAwait(false);
Scheduler.Add(() =>
await Task.Run(async () =>
{
if (Room == null)
return;
await PopulateUser(user).ConfigureAwait(false);
// for sanity, ensure that there can be no duplicate users in the room user list.
if (Room.Users.Any(existing => existing.UserID == user.UserID))
return;
Scheduler.Add(() =>
{
if (Room == null)
return;
Room.Users.Add(user);
// for sanity, ensure that there can be no duplicate users in the room user list.
if (Room.Users.Any(existing => existing.UserID == user.UserID))
return;
UserJoined?.Invoke(user);
RoomUpdated?.Invoke();
}, false);
Room.Users.Add(user);
UserJoined?.Invoke(user);
RoomUpdated?.Invoke();
});
}).ConfigureAwait(false);
}
Task IMultiplayerClient.UserLeft(MultiplayerRoomUser user) =>

View File

@ -53,7 +53,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
public MultiplayerRoomUser AddUser(User user, bool markAsPlaying = false)
{
var roomUser = new MultiplayerRoomUser(user.Id) { User = user };
((IMultiplayerClient)this).UserJoined(roomUser);
addUser(roomUser);
if (markAsPlaying)
PlayingUserIds.Add(user.Id);
@ -61,7 +62,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
return roomUser;
}
public void AddNullUser() => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(TestUserLookupCache.NULL_USER_ID));
public void AddNullUser() => addUser(new MultiplayerRoomUser(TestUserLookupCache.NULL_USER_ID));
private void addUser(MultiplayerRoomUser user)
{
((IMultiplayerClient)this).UserJoined(user).Wait();
// We want the user to be immediately available for testing, so force a scheduler update.
Scheduler.Update();
}
public void RemoveUser(User user)
{