1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 23:42:55 +08:00

Use polling connector in tests

This commit is contained in:
Dan Balasescu 2022-10-28 18:08:08 +09:00
parent 527b1d9db1
commit 169bcc2654
9 changed files with 44 additions and 17 deletions

View File

@ -13,6 +13,7 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.Polling;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Chat namespace osu.Game.Tests.Chat
@ -151,7 +152,7 @@ namespace osu.Game.Tests.Chat
public ChannelManagerContainer(IAPIProvider apiProvider) public ChannelManagerContainer(IAPIProvider apiProvider)
{ {
InternalChild = ChannelManager = new ChannelManager(apiProvider); InternalChild = ChannelManager = new ChannelManager(apiProvider, new PollingNotificationsClientConnector(apiProvider));
} }
} }
} }

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.Polling;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osuTK.Graphics; using osuTK.Graphics;
@ -41,11 +42,13 @@ namespace osu.Game.Tests.Visual.Online
{ {
linkColour = colours.Blue; linkColour = colours.Blue;
var chatManager = new ChannelManager(API); var chatManager = new ChannelManager(API, new PollingNotificationsClientConnector(API));
BindableList<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels; BindableList<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english" }); availableChannels.Add(new Channel { Name = "#english" });
availableChannels.Add(new Channel { Name = "#japanese" }); availableChannels.Add(new Channel { Name = "#japanese" });
Dependencies.Cache(chatManager); Dependencies.Cache(chatManager);
Add(chatManager);
} }
[SetUp] [SetUp]

View File

@ -24,6 +24,7 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.Polling;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osu.Game.Overlays.Chat.Listing; using osu.Game.Overlays.Chat.Listing;
@ -59,7 +60,7 @@ namespace osu.Game.Tests.Visual.Online
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] CachedDependencies = new (Type, object)[]
{ {
(typeof(ChannelManager), channelManager = new ChannelManager(API)), (typeof(ChannelManager), channelManager = new ChannelManager(API, new PollingNotificationsClientConnector(API))),
}, },
Children = new Drawable[] Children = new Drawable[]
{ {

View File

@ -16,6 +16,7 @@ using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.Polling;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
using osuTK.Input; using osuTK.Input;
@ -250,7 +251,7 @@ namespace osu.Game.Tests.Visual.Online
public TestContainer(IAPIProvider api, Channel[] channels) public TestContainer(IAPIProvider api, Channel[] channels)
{ {
this.channels = channels; this.channels = channels;
ChannelManager = new ChannelManager(api); ChannelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api));
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -15,6 +15,7 @@ using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Notifications.Polling;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osuTK.Input; using osuTK.Input;
@ -56,7 +57,9 @@ namespace osu.Game.Tests.Visual.Online
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
Add(channelManager = new ChannelManager(parent.Get<IAPIProvider>())); var api = parent.Get<IAPIProvider>();
Add(channelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api)));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));

View File

@ -9,6 +9,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.WebSocket;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osu.Game.Tournament.IPC; using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
@ -48,7 +49,7 @@ namespace osu.Game.Tournament.Components
if (manager == null) if (manager == null)
{ {
AddInternal(manager = new ChannelManager(api)); AddInternal(manager = new ChannelManager(api, new WebSocketNotificationsClientConnector(api)));
Channel.BindTo(manager.CurrentChannel); Channel.BindTo(manager.CurrentChannel);
} }

View File

@ -65,20 +65,20 @@ namespace osu.Game.Online.Chat
public IBindableList<Channel> AvailableChannels => availableChannels; public IBindableList<Channel> AvailableChannels => availableChannels;
private readonly IAPIProvider api; private readonly IAPIProvider api;
private readonly NotificationsClientConnector connector;
[Resolved] [Resolved]
private UserLookupCache users { get; set; } private UserLookupCache users { get; set; }
[Resolved]
private NotificationsClientConnector connector { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>(); private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private bool channelsInitialised; private bool channelsInitialised;
private ScheduledDelegate ackDelegate; private ScheduledDelegate ackDelegate;
public ChannelManager(IAPIProvider api) public ChannelManager(IAPIProvider api, NotificationsClientConnector connector)
{ {
this.api = api; this.api = api;
this.connector = connector;
CurrentChannel.ValueChanged += currentChannelChanged; CurrentChannel.ValueChanged += currentChannelChanged;
} }
@ -603,6 +603,12 @@ namespace osu.Game.Online.Chat
api.Queue(req); api.Queue(req);
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
connector?.Dispose();
}
} }
/// <summary> /// <summary>

View File

@ -6,13 +6,12 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Online.API; using osu.Game.Online.API;
namespace osu.Game.Online namespace osu.Game.Online
{ {
public abstract class SocketClientConnector : Component public abstract class SocketClientConnector : IDisposable
{ {
/// <summary> /// <summary>
/// Whether this is connected to the hub, use <see cref="CurrentConnection"/> to access the connection, if this is <c>true</c>. /// Whether this is connected to the hub, use <see cref="CurrentConnection"/> to access the connection, if this is <c>true</c>.
@ -173,11 +172,23 @@ namespace osu.Game.Online
public override string ToString() => $"{ClientName} ({(IsConnected.Value ? "connected" : "not connected")})"; public override string ToString() => $"{ClientName} ({(IsConnected.Value ? "connected" : "not connected")})";
protected override void Dispose(bool isDisposing) private bool isDisposed;
protected virtual void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); if (isDisposed)
return;
apiState.UnbindAll(); apiState.UnbindAll();
cancelExistingConnect(); cancelExistingConnect();
isDisposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
} }
} }
} }

View File

@ -45,7 +45,7 @@ using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Notifications; using osu.Game.Online.Notifications;
using osu.Game.Online.Notifications.Polling; using osu.Game.Online.Notifications.WebSocket;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Music; using osu.Game.Overlays.Music;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
@ -757,6 +757,7 @@ namespace osu.Game
BackButton.Receptor receptor; BackButton.Receptor receptor;
dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); dependencies.CacheAs(idleTracker = new GameIdleTracker(6000));
dependencies.CacheAs(notificationsClient = new WebSocketNotificationsClientConnector(API));
var sessionIdleTracker = new GameIdleTracker(300000); var sessionIdleTracker = new GameIdleTracker(300000);
sessionIdleTracker.IsIdle.BindValueChanged(idle => sessionIdleTracker.IsIdle.BindValueChanged(idle =>
@ -883,8 +884,7 @@ namespace osu.Game
loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true); loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true);
loadComponentSingleFile(news = new NewsOverlay(), overlayContent.Add, true); loadComponentSingleFile(news = new NewsOverlay(), overlayContent.Add, true);
var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true); var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true);
loadComponentSingleFile(notificationsClient = new PollingNotificationsClientConnector(API), AddInternal, true); loadComponentSingleFile(channelManager = new ChannelManager(API, notificationsClient), AddInternal, true);
loadComponentSingleFile(channelManager = new ChannelManager(API), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true); loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
loadComponentSingleFile(new MessageNotifier(), AddInternal, true); loadComponentSingleFile(new MessageNotifier(), AddInternal, true);
loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true); loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true);