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

Merge branch 'master' into rework-multiplayer-test-scenes

This commit is contained in:
Dean Herbert 2021-06-30 13:49:05 +09:00 committed by GitHub
commit a019f2cc5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 149 additions and 15 deletions

View File

@ -195,7 +195,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private void addSeekStep(double time)
{
AddStep($"seek to {time}", () => MusicController.SeekTo(time));
AddStep($"seek to {time}", () => Player.GameplayClockContainer.Seek(time));
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, Player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
}

View File

@ -217,7 +217,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private void addSeekStep(double time)
{
AddStep($"seek to {time}", () => MusicController.SeekTo(time));
AddStep($"seek to {time}", () => Player.GameplayClockContainer.Seek(time));
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, Player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
}

View File

@ -0,0 +1,105 @@
// 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.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Tests.Visual;
using osu.Game.Users;
namespace osu.Game.Tests.Chat
{
[HeadlessTest]
public class TestSceneChannelManager : OsuTestScene
{
private ChannelManager channelManager;
private int currentMessageId;
[SetUp]
public void Setup() => Schedule(() =>
{
var container = new ChannelManagerContainer();
Child = container;
channelManager = container.ChannelManager;
});
[SetUpSteps]
public void SetUpSteps()
{
AddStep("register request handling", () =>
{
currentMessageId = 0;
((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case JoinChannelRequest joinChannel:
joinChannel.TriggerSuccess();
return true;
case PostMessageRequest postMessage:
postMessage.TriggerSuccess(new Message(++currentMessageId)
{
IsAction = postMessage.Message.IsAction,
ChannelId = postMessage.Message.ChannelId,
Content = postMessage.Message.Content,
Links = postMessage.Message.Links,
Timestamp = postMessage.Message.Timestamp,
Sender = postMessage.Message.Sender
});
return true;
}
return false;
};
});
}
[Test]
public void TestCommandsPostedToCorrectChannelWhenNotCurrent()
{
Channel channel1 = null;
Channel channel2 = null;
AddStep("join 2 rooms", () =>
{
channelManager.JoinChannel(channel1 = createChannel(1, ChannelType.Public));
channelManager.JoinChannel(channel2 = createChannel(2, ChannelType.Public));
});
AddStep("select channel 1", () => channelManager.CurrentChannel.Value = channel1);
AddStep("post /me command to channel 2", () => channelManager.PostCommand("me dances", channel2));
AddAssert("/me command received by channel 2", () => channel2.Messages.Last().Content == "dances");
AddStep("post /np command to channel 2", () => channelManager.PostCommand("np", channel2));
AddAssert("/np command received by channel 2", () => channel2.Messages.Last().Content.Contains("is listening to"));
}
private Channel createChannel(int id, ChannelType type) => new Channel(new User())
{
Id = id,
Name = $"Channel {id}",
Topic = $"Topic of channel {id} with type {type}",
Type = type,
};
private class ChannelManagerContainer : CompositeDrawable
{
[Cached]
public ChannelManager ChannelManager { get; } = new ChannelManager();
public ChannelManagerContainer()
{
InternalChild = ChannelManager;
}
}
}
}

View File

@ -17,7 +17,8 @@ namespace osu.Game.Tests
protected virtual TestOsuGameBase LoadOsuIntoHost(GameHost host, bool withBeatmap = false)
{
var osu = new TestOsuGameBase(withBeatmap);
Task.Run(() => host.Run(osu));
Task.Run(() => host.Run(osu))
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");

View File

@ -82,7 +82,8 @@ namespace osu.Game.Tests.Visual.Online
{
switch (req)
{
case JoinChannelRequest _:
case JoinChannelRequest joinChannel:
joinChannel.TriggerSuccess();
return true;
}

View File

@ -149,7 +149,8 @@ namespace osu.Game.Tournament.Tests.NonVisual
private TournamentGameBase loadOsu(GameHost host)
{
var osu = new TournamentGameBase();
Task.Run(() => host.Run(osu));
Task.Run(() => host.Run(osu))
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
return osu;
}

View File

@ -55,7 +55,8 @@ namespace osu.Game.Tournament.Tests.NonVisual
private TournamentGameBase loadOsu(GameHost host)
{
var osu = new TournamentGameBase();
Task.Run(() => host.Run(osu));
Task.Run(() => host.Run(osu))
.ContinueWith(t => Assert.Fail($"Host threw exception {t.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
waitForOrAssert(() => osu.IsLoaded, @"osu! failed to start in a reasonable amount of time");
return osu;
}

View File

@ -89,12 +89,18 @@ namespace osu.Game.Database
if (IsDisposed)
throw new ObjectDisposedException(nameof(RealmContextFactory));
Logger.Log(@"Blocking realm operations.", LoggingTarget.Database);
blockingLock.Wait();
flushContexts();
return new InvokeOnDisposal<RealmContextFactory>(this, endBlockingSection);
static void endBlockingSection(RealmContextFactory factory) => factory.blockingLock.Release();
static void endBlockingSection(RealmContextFactory factory)
{
factory.blockingLock.Release();
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
}
}
protected override void Update()
@ -147,6 +153,8 @@ namespace osu.Game.Database
private void flushContexts()
{
Logger.Log(@"Flushing realm contexts...", LoggingTarget.Database);
var previousContext = context;
context = null;
@ -155,6 +163,8 @@ namespace osu.Game.Database
Thread.Sleep(50);
previousContext?.Dispose();
Logger.Log(@"Realm contexts flushed.", LoggingTarget.Database);
}
protected override void Dispose(bool isDisposing)

View File

@ -9,11 +9,11 @@ namespace osu.Game.Online.API.Requests
{
public class PostMessageRequest : APIRequest<Message>
{
private readonly Message message;
public readonly Message Message;
public PostMessageRequest(Message message)
{
this.message = message;
Message = message;
}
protected override WebRequest CreateWebRequest()
@ -21,12 +21,12 @@ namespace osu.Game.Online.API.Requests
var req = base.CreateWebRequest();
req.Method = HttpMethod.Post;
req.AddParameter(@"is_action", message.IsAction.ToString().ToLowerInvariant());
req.AddParameter(@"message", message.Content);
req.AddParameter(@"is_action", Message.IsAction.ToString().ToLowerInvariant());
req.AddParameter(@"message", Message.Content);
return req;
}
protected override string Target => $@"chat/channels/{message.ChannelId}/messages";
protected override string Target => $@"chat/channels/{Message.ChannelId}/messages";
}
}

View File

@ -225,7 +225,7 @@ namespace osu.Game.Online.Chat
switch (command)
{
case "np":
AddInternal(new NowPlayingCommand());
AddInternal(new NowPlayingCommand(target));
break;
case "me":
@ -235,7 +235,7 @@ namespace osu.Game.Online.Chat
break;
}
PostMessage(content, true);
PostMessage(content, true, target);
break;
case "join":

View File

@ -21,6 +21,17 @@ namespace osu.Game.Online.Chat
[Resolved]
private Bindable<WorkingBeatmap> currentBeatmap { get; set; }
private readonly Channel target;
/// <summary>
/// Creates a new <see cref="NowPlayingCommand"/> to post the currently-playing beatmap to a parenting <see cref="IChannelPostTarget"/>.
/// </summary>
/// <param name="target">The target channel to post to. If <c>null</c>, the currently-selected channel will be posted to.</param>
public NowPlayingCommand(Channel target = null)
{
this.target = target;
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -48,7 +59,7 @@ namespace osu.Game.Online.Chat
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[{api.WebsiteRootUrl}/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
channelManager.PostMessage($"is {verb} {beatmapString}", true);
channelManager.PostMessage($"is {verb} {beatmapString}", true, target);
Expire();
}
}

View File

@ -422,11 +422,15 @@ namespace osu.Game
public void Migrate(string path)
{
Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""...");
using (realmFactory.BlockAllOperations())
{
contextFactory.FlushConnections();
(Storage as OsuStorage)?.Migrate(Host.GetStorage(path));
}
Logger.Log(@"Migration complete!");
}
protected override UserInputManager CreateUserInputManager() => new OsuUserInputManager();