From 501bc4be049ce5112383c132ef836b64b42426b0 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Thu, 22 Jun 2023 15:44:11 +1200 Subject: [PATCH] Try fix random TestGhostToAghost test failures (#17546) --- .../Tests/Minds/MindTests.EntityDeletion.cs | 50 ++++++------------- .../Tests/Minds/MindTests.Helpers.cs | 7 ++- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/Content.IntegrationTests/Tests/Minds/MindTests.EntityDeletion.cs b/Content.IntegrationTests/Tests/Minds/MindTests.EntityDeletion.cs index e23ca32756..32e6d3d273 100644 --- a/Content.IntegrationTests/Tests/Minds/MindTests.EntityDeletion.cs +++ b/Content.IntegrationTests/Tests/Minds/MindTests.EntityDeletion.cs @@ -202,53 +202,31 @@ public sealed partial class MindTests [Test] public async Task TestGhostToAghost() { - // Client is needed to spawn session - await using var pairTracker = await PoolManager.GetServerClient(); + await using var pairTracker = await SetupPair(); var server = pairTracker.Pair.Server; - var entMan = server.ResolveDependency(); var playerMan = server.ResolveDependency(); var serverConsole = server.ResolveDependency(); - IPlayerSession player = playerMan.ServerSessions.Single(); + var player = playerMan.ServerSessions.Single(); - EntityUid ghost = default!; + var ghost = await BecomeGhost(pairTracker.Pair); - await server.WaitAssertion(() => - { - Assert.That(player.AttachedEntity, Is.Not.EqualTo(null)); - entMan.DeleteEntity(player.AttachedEntity!.Value); - }); + // Player is a normal ghost (not admin ghost). + Assert.That(entMan.GetComponent(player.AttachedEntity!.Value).EntityPrototype?.ID, Is.Not.EqualTo("AdminObserver")); + // Try to become an admin ghost + await server.WaitAssertion(() => serverConsole.ExecuteCommand(player, "aghost")); await PoolManager.RunTicksSync(pairTracker.Pair, 5); - await server.WaitAssertion(() => - { - // Is player a ghost? - Assert.That(player.AttachedEntity, Is.Not.EqualTo(null)); - ghost = player.AttachedEntity!.Value; - Assert.That(entMan.HasComponent(ghost)); - }); + Assert.That(entMan.Deleted(ghost), "old ghost was not deleted"); + Assert.That(player.AttachedEntity, Is.Not.EqualTo(ghost), "Player is still attached to the old ghost"); + Assert.That(entMan.HasComponent(player.AttachedEntity!.Value), "Player did not become a new ghost"); + Assert.That(entMan.GetComponent(player.AttachedEntity.Value).EntityPrototype?.ID, Is.EqualTo("AdminObserver")); - await PoolManager.RunTicksSync(pairTracker.Pair, 5); - - await server.WaitAssertion(() => - { - serverConsole.ExecuteCommand(player, "aghost"); - }); - - await PoolManager.RunTicksSync(pairTracker.Pair, 5); - - await server.WaitAssertion(() => - { - Assert.That(entMan.Deleted(ghost)); - Assert.That(player.AttachedEntity, Is.Not.EqualTo(ghost)); - Assert.That(entMan.HasComponent(player.AttachedEntity!.Value)); - - var mind = player.ContentData()?.Mind; - Assert.NotNull(mind); - Assert.Null(mind.VisitingEntity); - }); + var mind = player.ContentData()?.Mind; + Assert.NotNull(mind); + Assert.Null(mind.VisitingEntity); await pairTracker.CleanReturnAsync(); } diff --git a/Content.IntegrationTests/Tests/Minds/MindTests.Helpers.cs b/Content.IntegrationTests/Tests/Minds/MindTests.Helpers.cs index 51d451451a..b3b77451fe 100644 --- a/Content.IntegrationTests/Tests/Minds/MindTests.Helpers.cs +++ b/Content.IntegrationTests/Tests/Minds/MindTests.Helpers.cs @@ -18,8 +18,13 @@ namespace Content.IntegrationTests.Tests.Minds; public sealed partial class MindTests { /// - /// Gets a server-client pair and ensures that the client is attached to a simple mind test entity. + /// Gets a server-client pair and ensures that the client is attached to a simple mind test entity. /// + /// + /// Without this, it may be possible that a tests starts with the client attached to an entity that does not match + /// the player's mind's current entity, likely because some previous test directly changed the players attached + /// entity. + /// public async Task SetupPair() { var pairTracker = await PoolManager.GetServerClient();