Make pardon command test non-destructive (#18518)

This commit is contained in:
Leon Friedrich
2023-08-02 12:57:11 +12:00
committed by GitHub
parent 9cc2852040
commit 7ce68629bc

View File

@@ -2,6 +2,7 @@ using System.Linq;
using Content.Server.Database; using Content.Server.Database;
using Robust.Server.Console; using Robust.Server.Console;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Network;
namespace Content.IntegrationTests.Tests.Commands namespace Content.IntegrationTests.Tests.Commands
{ {
@@ -14,18 +15,20 @@ namespace Content.IntegrationTests.Tests.Commands
[Test] [Test]
public async Task PardonTest() public async Task PardonTest()
{ {
await using var pairTracker = await PoolManager.GetServerClient(new() { Destructive = true }); await using var pairTracker = await PoolManager.GetServerClient();
var server = pairTracker.Pair.Server; var server = pairTracker.Pair.Server;
var client = pairTracker.Pair.Client;
var sPlayerManager = server.ResolveDependency<IPlayerManager>(); var sPlayerManager = server.ResolveDependency<IPlayerManager>();
var sConsole = server.ResolveDependency<IServerConsoleHost>(); var sConsole = server.ResolveDependency<IServerConsoleHost>();
var sDatabase = server.ResolveDependency<IServerDbManager>(); var sDatabase = server.ResolveDependency<IServerDbManager>();
var netMan = client.ResolveDependency<IClientNetManager>();
await server.WaitAssertion(async () =>
{
var clientSession = sPlayerManager.Sessions.Single(); var clientSession = sPlayerManager.Sessions.Single();
var clientId = clientSession.UserId; var clientId = clientSession.UserId;
Assert.That(netMan.IsConnected);
Assert.That(sPlayerManager.Sessions.Count(), Is.EqualTo(1));
// No bans on record // No bans on record
Assert.Multiple(async () => Assert.Multiple(async () =>
{ {
@@ -35,7 +38,7 @@ namespace Content.IntegrationTests.Tests.Commands
}); });
// Try to pardon a ban that does not exist // Try to pardon a ban that does not exist
sConsole.ExecuteCommand("pardon 1"); await server.WaitPost(() => sConsole.ExecuteCommand("pardon 1"));
// Still no bans on record // Still no bans on record
Assert.Multiple(async () => Assert.Multiple(async () =>
@@ -47,8 +50,9 @@ namespace Content.IntegrationTests.Tests.Commands
var banReason = "test"; var banReason = "test";
Assert.That(sPlayerManager.Sessions.Count(), Is.EqualTo(1));
// Ban the client for 24 hours // Ban the client for 24 hours
sConsole.ExecuteCommand($"ban {clientSession.Name} {banReason} 1440"); await server.WaitPost(() => sConsole.ExecuteCommand($"ban {clientSession.Name} {banReason} 1440"));
// Should have one ban on record now // Should have one ban on record now
Assert.Multiple(async () => Assert.Multiple(async () =>
@@ -58,8 +62,12 @@ namespace Content.IntegrationTests.Tests.Commands
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null), Has.Count.EqualTo(1)); Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null), Has.Count.EqualTo(1));
}); });
await PoolManager.RunTicksSync(pairTracker.Pair, 5);
Assert.That(sPlayerManager.Sessions.Count(), Is.EqualTo(0));
Assert.That(!netMan.IsConnected);
// Try to pardon a ban that does not exist // Try to pardon a ban that does not exist
sConsole.ExecuteCommand("pardon 2"); await server.WaitPost(() => sConsole.ExecuteCommand("pardon 2"));
// The existing ban is unaffected // The existing ban is unaffected
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null), Is.Not.Null); Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null), Is.Not.Null);
@@ -84,7 +92,7 @@ namespace Content.IntegrationTests.Tests.Commands
}); });
// Pardon the actual ban // Pardon the actual ban
sConsole.ExecuteCommand("pardon 1"); await server.WaitPost(() => sConsole.ExecuteCommand("pardon 1"));
// No bans should be returned // No bans should be returned
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null), Is.Null); Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null), Is.Null);
@@ -119,7 +127,7 @@ namespace Content.IntegrationTests.Tests.Commands
}); });
// Try to pardon it again // Try to pardon it again
sConsole.ExecuteCommand("pardon 1"); await server.WaitPost(() => sConsole.ExecuteCommand("pardon 1"));
// Nothing changes // Nothing changes
Assert.Multiple(async () => Assert.Multiple(async () =>
@@ -133,7 +141,14 @@ namespace Content.IntegrationTests.Tests.Commands
// The list is still returned since that ignores pardons // The list is still returned since that ignores pardons
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null), Has.Count.EqualTo(1)); Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null), Has.Count.EqualTo(1));
}); });
});
// Reconnect client. Slightly faster than dirtying the pair.
Assert.That(sPlayerManager.Sessions.Count(), Is.EqualTo(0));
client.SetConnectTarget(server);
await client.WaitPost(() => netMan.ClientConnect(null!, 0, null!));
await PoolManager.ReallyBeIdle(pairTracker.Pair);
Assert.That(sPlayerManager.Sessions.Count(), Is.EqualTo(1));
await pairTracker.CleanReturnAsync(); await pairTracker.CleanReturnAsync();
} }
} }