mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 00:09:55 +09:00
Add ability to simulate network failures to TestSpectatorClient
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
@ -20,10 +21,15 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
public class TestSpectatorClient : SpectatorClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum number of frames sent per bundle via <see cref="SendFrames"/>.
|
||||
/// Maximum number of frames sent per bundle via <see cref="SendFramesFromUser"/>.
|
||||
/// </summary>
|
||||
public const int FRAME_BUNDLE_SIZE = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to force send operations to fail (simulating a network issue).
|
||||
/// </summary>
|
||||
public bool ShouldFailSendingFrames { get; set; }
|
||||
|
||||
public override IBindable<bool> IsConnected { get; } = new Bindable<bool>(true);
|
||||
|
||||
public IReadOnlyDictionary<int, ReplayFrame> LastReceivedUserFrames => lastReceivedUserFrames;
|
||||
@ -75,10 +81,12 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
|
||||
/// <summary>
|
||||
/// Sends frames for an arbitrary user, in bundles containing 10 frames each.
|
||||
/// This bypasses the standard queueing mechanism completely and should only be used to test cases where multiple users need to be sending data.
|
||||
/// Importantly, <see cref="ShouldFailSendingFrames"/> will have no effect.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user to send frames for.</param>
|
||||
/// <param name="count">The total number of frames to send.</param>
|
||||
public void SendFrames(int userId, int count)
|
||||
public void SendFramesFromUser(int userId, int count)
|
||||
{
|
||||
var frames = new List<LegacyReplayFrame>();
|
||||
|
||||
@ -120,7 +128,13 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
return ((ISpectatorClient)this).UserBeganPlaying(api.LocalUser.Value.Id, state);
|
||||
}
|
||||
|
||||
protected override Task SendFramesInternal(FrameDataBundle data) => ((ISpectatorClient)this).UserSentFrames(api.LocalUser.Value.Id, data);
|
||||
protected override Task SendFramesInternal(FrameDataBundle bundle)
|
||||
{
|
||||
if (ShouldFailSendingFrames)
|
||||
return Task.FromException(new InvalidOperationException());
|
||||
|
||||
return ((ISpectatorClient)this).UserSentFrames(api.LocalUser.Value.Id, bundle);
|
||||
}
|
||||
|
||||
protected override Task EndPlayingInternal(SpectatorState state) => ((ISpectatorClient)this).UserFinishedPlaying(api.LocalUser.Value.Id, state);
|
||||
|
||||
|
Reference in New Issue
Block a user