Try fix random TestGhostToAghost test failures (#17546)

This commit is contained in:
Leon Friedrich
2023-06-22 15:44:11 +12:00
committed by GitHub
parent 7a338265ad
commit 501bc4be04
2 changed files with 20 additions and 37 deletions

View File

@@ -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<IServerEntityManager>();
var playerMan = server.ResolveDependency<IPlayerManager>();
var serverConsole = server.ResolveDependency<IServerConsoleHost>();
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<MetaDataComponent>(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<GhostComponent>(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<GhostComponent>(player.AttachedEntity!.Value), "Player did not become a new ghost");
Assert.That(entMan.GetComponent<MetaDataComponent>(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<GhostComponent>(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();
}

View File

@@ -18,8 +18,13 @@ namespace Content.IntegrationTests.Tests.Minds;
public sealed partial class MindTests
{
/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public async Task<PairTracker> SetupPair()
{
var pairTracker = await PoolManager.GetServerClient();