Files
RobustToolbox/Robust.UnitTesting/Shared/Networking/DisconnectTest.cs
Pieter-Jan Briers 0094040d68 Dependency update / fixes / skrungle bungle (#4825)
* Move to Central Package Management.

Allows us to store NuGet package versions all in one place. Yay!

* Update NuGet packages and fix code for changes.

Notable:

Changes to ILVerify.
Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality.
NUnit's analyzers are already complaining and I didn't even update it to 4.x yet.
TerraFX changed to GetLastSystemError so error handling had to be changed.
Buncha APIs have more NRT annotations.

* Remove dotnet-eng NuGet package source.

I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET.

* Fix double loading of assemblies due to ALC shenanigans.

Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust!

Chaos ensues.

We now try to forcibly prioritize loading from the default ALC first to avoid this.

* Remove Robust.Physics project.

Never used.

* Remove erroneous NVorbis reference.

Should be VorbisPizza and otherwise wasn't used.

* Sandbox fixes

* Remove unused unit test package references.

Castle.Core and NUnit.ConsoleRunner.

* Update NUnit to 4.0.1

This requires replacing all the old assertion methods because they removed them 🥲

* Mute CA1416 (platform check) errors

TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes.

* Fine ya cranky, no more CPM for Robust.Client.Injectors

* Changelog

* Oh so that's what dotnet-eng was used for. Yeah ok that makes sense.

* Central package management for remaining 2 robust projects

* Ok that was a bad idea let's just use NUnit 3 on the analyzer test project

* Oh right forgot to remove this one

* Update to a newer version of RemoteExecutor

* Disable RemoteExecutor test

https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it.

* Fix immutable list serialization
2024-01-12 22:59:52 +01:00

99 lines
3.2 KiB
C#

using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Server.Player;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.Shared.Player;
using cIPlayerManager = Robust.Client.Player.IPlayerManager;
using sIPlayerManager = Robust.Server.Player.IPlayerManager;
namespace Robust.UnitTesting.Shared.Networking;
public sealed class DisconnectTest : RobustIntegrationTest
{
/// <summary>
/// Check that client disconnection works as expected. This is effectively a test of
/// <see cref="RobustIntegrationTest.IntegrationNetManager"/>, not the main net manager.
/// </summary>
[Test]
[TestOf(typeof(IntegrationNetManager))]
public async Task TestConnectDisconnect()
{
var server = StartServer();
var client = StartClient();
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
var cNetMan = client.ResolveDependency<IClientNetManager>();
var cPlayerMan = client.ResolveDependency<cIPlayerManager>();
var sPlayerMan = server.ResolveDependency<sIPlayerManager>();
ICommonSession session = default!;
AssertDisconnected();
// Connect client.
Assert.DoesNotThrow(() => client.SetConnectTarget(server));
await client.WaitPost(() => cNetMan.ClientConnect(null!, 0, null!));
await RunTicks();
AssertConnected();
// Disconnect the client
cNetMan.ClientDisconnect("test");
await RunTicks();
AssertDisconnected();
// Reconnect again
Assert.DoesNotThrow(() => client.SetConnectTarget(server));
await client.WaitPost(() => cNetMan.ClientConnect(null!, 0, null!));
await RunTicks();
AssertConnected();
// Disconnect again, but using the server-channel
session.Channel.Disconnect("test 2");
await RunTicks();
AssertDisconnected();
// Reconnect again
Assert.DoesNotThrow(() => client.SetConnectTarget(server));
await client.WaitPost(() => cNetMan.ClientConnect(null!, 0, null!));
await RunTicks();
AssertConnected();
void AssertConnected()
{
Assert.That(cNetMan.IsConnected, Is.True);
Assert.That(sPlayerMan.Sessions.Count(), Is.EqualTo(1));
session = sPlayerMan.Sessions.Single();
Assert.That(session.Status, Is.EqualTo(SessionStatus.Connected));
Assert.That(session.UserId, Is.EqualTo(cPlayerMan!.LocalPlayer?.UserId));
Assert.That(cPlayerMan.LocalPlayer, Is.Not.Null);
}
void AssertDisconnected()
{
Assert.That(cNetMan.IsConnected, Is.False);
Assert.That(sPlayerMan.Sessions.Count(), Is.EqualTo(0));
if (session != null)
Assert.That(session.Status, Is.EqualTo(SessionStatus.Disconnected));
}
async Task RunTicks()
{
for (int i = 0; i < 10; i++)
{
await server.WaitRunTicks(1);
await client.WaitRunTicks(1);
}
}
}
}