Files
tbd-station-14/Content.IntegrationTests/Tests/Pathfinding/PathfindingChunkTest.cs
Javier Guardia Fernández 1508efff54 Add test pooling (#4961)
* Add test pooling

* WIP test pooling changes

* Fix Destructible tests

* Don't pool unpooled or dummy ticker instances

* Change ServerPathfindingDebugSystem to replace existing entries

* Fix SaveLoadSaveTest comment

* Don't pool StartTest

* Comment out global setup

* Fix puddle tests

* Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit

* Update RobustToolbox

* Finish fixing tests, make test threads background threads

* Bring back pooling

* Fix nullable

* Update RobustToolbox

* Set cvars on server return

* Un-pool tests with custom cvars

* Update RobustToolbox

* Update RobustToolbox

* Change where the main tile coordinates are

* Remove DisposalUnitTest grid check

* Fix test pooling being a fickle bitch

* Fix EntitySystemExtensionsTest

* Update RobustToolbox

* Update RobustToolbox

* Make nullable pool settings true

* Update RobustToolbox

* Wait other way around

* We are unitystation now

* Update RobustToolbox

* Create global setup

* Pool some more tests

* Fix not properly disconnecting clients before restarting the round

* Give more info on ran tests

* Standardize default test cvars

* Update RobustToolbox

* Update RobustToolbox

* Pool clients

* Fix test order issue

* Fix cvars in character creation test not being set properly

* Update RobustToolbox

* Update RobustToolbox

* Rider shut

* Update RobustToolbox

* Format tests ran better

* Update RobustToolbox

* Reset RobustToolbox

* Reset RobustToolbox harder

* Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00

63 lines
2.5 KiB
C#

using System.Linq;
using System.Threading.Tasks;
using Content.Server.AI.Pathfinding;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Pathfinding
{
[TestFixture]
[TestOf(typeof(PathfindingChunk))]
public class PathfindingChunkTest : ContentIntegrationTest
{
[Test]
public async Task Test()
{
var server = StartServer();
server.Assert(() =>
{
var pathfindingSystem = EntitySystem.Get<PathfindingSystem>();
var mapMan = IoCManager.Resolve<IMapManager>();
// Setup
var grid = GetMainGrid(mapMan);
var chunkTile = grid.GetTileRef(new Vector2i(0, 0));
var chunk = pathfindingSystem.GetChunk(chunkTile);
Assert.That(chunk.Nodes.Length == PathfindingChunk.ChunkSize * PathfindingChunk.ChunkSize);
// Neighbors
var chunkNeighbors = chunk.GetNeighbors().ToList();
Assert.That(chunkNeighbors.Count == 0);
var neighborChunkTile = grid.GetTileRef(new Vector2i(PathfindingChunk.ChunkSize, PathfindingChunk.ChunkSize));
var neighborChunk = pathfindingSystem.GetChunk(neighborChunkTile);
chunkNeighbors = chunk.GetNeighbors().ToList();
Assert.That(chunkNeighbors.Count == 1);
// Directions
Assert.That(PathfindingHelpers.RelativeDirection(neighborChunk, chunk) == Direction.NorthEast);
Assert.That(PathfindingHelpers.RelativeDirection(chunk.Nodes[0, 1], chunk.Nodes[0, 0]) == Direction.North);
// Nodes
var node = chunk.Nodes[1, 1];
var nodeNeighbors = node.GetNeighbors().ToList();
Assert.That(nodeNeighbors.Count == 8);
// Bottom-left corner with no chunk neighbor
node = chunk.Nodes[0, 0];
nodeNeighbors = node.GetNeighbors().ToList();
Assert.That(nodeNeighbors.Count == 3);
// Given we have 1 NE neighbor then NE corner should have 4 neighbors due to the 1 extra from the neighbor chunk
node = chunk.Nodes[PathfindingChunk.ChunkSize - 1, PathfindingChunk.ChunkSize - 1];
nodeNeighbors = node.GetNeighbors().ToList();
Assert.That(nodeNeighbors.Count == 4);
});
await server.WaitIdleAsync();
}
}
}