2020-12-19 01:02:47 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
using System;
|
2020-12-19 01:02:47 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
2020-12-19 01:17:07 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-03-03 18:40:19 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2020-12-19 01:02:47 +08:00
|
|
|
|
2020-12-25 12:20:37 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-19 01:02:47 +08:00
|
|
|
{
|
2020-12-19 01:17:07 +08:00
|
|
|
[HeadlessTest]
|
2020-12-25 21:18:21 +08:00
|
|
|
public class TestSceneMultiplayerRoomManager : RoomTestScene
|
2020-12-19 01:02:47 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
private TestMultiplayerRoomContainer roomContainer;
|
|
|
|
private TestMultiplayerRoomManager roomManager => roomContainer.RoomManager;
|
2020-12-19 01:02:47 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPollsInitially()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a few rooms", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom(r => r.Name.Value = "1"));
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom(r => r.Name.Value = "2"));
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
|
|
|
roomManager.ClearRooms();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
AddAssert("manager polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 2);
|
2020-12-19 01:02:47 +08:00
|
|
|
AddAssert("initial rooms received", () => roomManager.InitialRoomsReceived.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRoomsClearedOnDisconnection()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a few rooms", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("disconnect", () => roomContainer.Client.Disconnect());
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
AddAssert("rooms cleared", () => ((RoomManager)roomManager).Rooms.Count == 0);
|
2020-12-19 01:02:47 +08:00
|
|
|
AddAssert("initial rooms not received", () => !roomManager.InitialRoomsReceived.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRoomsPolledOnReconnect()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a few rooms", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.PartRoom();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("disconnect", () => roomContainer.Client.Disconnect());
|
|
|
|
AddStep("connect", () => roomContainer.Client.Connect());
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
AddAssert("manager polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 2);
|
2020-12-19 01:02:47 +08:00
|
|
|
AddAssert("initial rooms received", () => roomManager.InitialRoomsReceived.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestRoomsNotPolledWhenJoined()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a room", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:02:47 +08:00
|
|
|
roomManager.ClearRooms();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
AddAssert("manager not polled for rooms", () => ((RoomManager)roomManager).Rooms.Count == 0);
|
2020-12-19 01:02:47 +08:00
|
|
|
AddAssert("initial rooms not received", () => !roomManager.InitialRoomsReceived.Value);
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:20:02 +08:00
|
|
|
[Test]
|
|
|
|
public void TestMultiplayerRoomJoinedWhenCreated()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a room", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:20:02 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-20 18:43:51 +08:00
|
|
|
AddUntilStep("multiplayer room joined", () => roomContainer.Client.Room != null);
|
2020-12-19 01:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultiplayerRoomPartedWhenAPIRoomParted()
|
|
|
|
{
|
|
|
|
AddStep("create room manager with a room", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
roomManager.CreateRoom(createRoom());
|
2020-12-19 01:20:02 +08:00
|
|
|
roomManager.PartRoom();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("multiplayer room parted", () => roomContainer.Client.Room == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2020-12-20 17:24:15 +08:00
|
|
|
public void TestMultiplayerRoomJoinedWhenAPIRoomJoined()
|
2020-12-19 01:20:02 +08:00
|
|
|
{
|
|
|
|
AddStep("create room manager with a room", () =>
|
|
|
|
{
|
|
|
|
createRoomManager().With(d => d.OnLoadComplete += _ =>
|
|
|
|
{
|
2021-03-03 18:40:19 +08:00
|
|
|
var r = createRoom();
|
2020-12-19 01:20:02 +08:00
|
|
|
roomManager.CreateRoom(r);
|
|
|
|
roomManager.PartRoom();
|
|
|
|
roomManager.JoinRoom(r);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-20 18:43:51 +08:00
|
|
|
AddUntilStep("multiplayer room joined", () => roomContainer.Client.Room != null);
|
2020-12-19 01:20:02 +08:00
|
|
|
}
|
|
|
|
|
2021-03-03 18:40:19 +08:00
|
|
|
private Room createRoom(Action<Room> initFunc = null)
|
|
|
|
{
|
|
|
|
var room = new Room();
|
|
|
|
|
|
|
|
room.Name.Value = "test room";
|
|
|
|
room.Playlist.Add(new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = new TestBeatmap(Ruleset.Value).BeatmapInfo },
|
|
|
|
Ruleset = { Value = Ruleset.Value }
|
|
|
|
});
|
|
|
|
|
|
|
|
initFunc?.Invoke(room);
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
private TestMultiplayerRoomManager createRoomManager()
|
2020-12-19 01:02:47 +08:00
|
|
|
{
|
2020-12-25 12:38:11 +08:00
|
|
|
Child = roomContainer = new TestMultiplayerRoomContainer
|
2020-12-19 01:02:47 +08:00
|
|
|
{
|
|
|
|
RoomManager =
|
|
|
|
{
|
|
|
|
TimeBetweenListingPolls = { Value = 1 },
|
2021-01-12 15:03:12 +08:00
|
|
|
TimeBetweenSelectionPolls = { Value = 1 }
|
2020-12-19 01:02:47 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return roomManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|