Files
tbd-station-14/Content.IntegrationTests/Tests/Fluids/PuddleTest.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

191 lines
6.4 KiB
C#

using System;
using System.Threading.Tasks;
using Content.Server.Fluids.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Coordinates;
using Content.Shared.FixedPoint;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.IntegrationTests.Tests.Fluids
{
[TestFixture]
[TestOf(typeof(PuddleComponent))]
public class PuddleTest : ContentIntegrationTest
{
[Test]
public async Task TilePuddleTest()
{
var server = StartServer();
await server.WaitIdleAsync();
var mapManager = server.ResolveDependency<IMapManager>();
server.Assert(() =>
{
var solution = new Solution("water", FixedPoint2.New(20));
var grid = GetMainGrid(mapManager);
var (x, y) = GetMainTile(grid).GridIndices;
var coordinates = new EntityCoordinates(grid.GridEntityId, x, y);
var puddle = solution.SpillAt(coordinates, "PuddleSmear");
Assert.NotNull(puddle);
});
await server.WaitIdleAsync();
}
[Test]
public async Task SpaceNoPuddleTest()
{
var server = StartServer();
await server.WaitIdleAsync();
var mapManager = server.ResolveDependency<IMapManager>();
IMapGrid grid = null;
// Remove all tiles
server.Post(() =>
{
grid = GetMainGrid(mapManager);
foreach (var tile in grid.GetAllTiles())
{
grid.SetTile(tile.GridIndices, Tile.Empty);
}
});
await server.WaitIdleAsync();
server.Assert(() =>
{
var coordinates = grid.ToCoordinates();
var solution = new Solution("water", FixedPoint2.New(20));
var puddle = solution.SpillAt(coordinates, "PuddleSmear");
Assert.Null(puddle);
});
await server.WaitIdleAsync();
}
[Test]
public async Task PuddlePauseTest()
{
var server = StartServer();
await server.WaitIdleAsync();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPauseManager = server.ResolveDependency<IPauseManager>();
var sTileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
var sGameTiming = server.ResolveDependency<IGameTiming>();
var sEntityManager = server.ResolveDependency<IEntityManager>();
MapId sMapId = default;
IMapGrid sGrid;
GridId sGridId = default;
IEntity sGridEntity = null;
EntityCoordinates sCoordinates = default;
// Spawn a paused map with one tile to spawn puddles on
await server.WaitPost(() =>
{
sMapId = sMapManager.CreateMap();
sPauseManager.SetMapPaused(sMapId, true);
sGrid = sMapManager.CreateGrid(sMapId);
sGridId = sGrid.Index;
sGridEntity = sEntityManager.GetEntity(sGrid.GridEntityId);
sGridEntity.Paused = true; // See https://github.com/space-wizards/RobustToolbox/issues/1444
var tileDefinition = sTileDefinitionManager["underplating"];
var tile = new Tile(tileDefinition.TileId);
sCoordinates = sGrid.ToCoordinates();
sGrid.SetTile(sCoordinates, tile);
});
// Check that the map and grid are paused
await server.WaitAssertion(() =>
{
Assert.True(sPauseManager.IsGridPaused(sGridId));
Assert.True(sPauseManager.IsMapPaused(sMapId));
Assert.True(sGridEntity.Paused);
});
float evaporateTime = default;
PuddleComponent puddle = null;
EvaporationComponent evaporation;
var amount = 2;
// Spawn a puddle
await server.WaitAssertion(() =>
{
var solution = new Solution("water", FixedPoint2.New(amount));
puddle = solution.SpillAt(sCoordinates, "PuddleSmear");
// Check that the puddle was created
Assert.NotNull(puddle);
evaporation = puddle.Owner.GetComponent<EvaporationComponent>();
puddle.Owner.Paused = true; // See https://github.com/space-wizards/RobustToolbox/issues/1445
Assert.True(puddle.Owner.Paused);
// Check that the puddle is going to evaporate
Assert.Positive(evaporation.EvaporateTime);
// Should have a timer component added to it for evaporation
Assert.That(evaporation.Accumulator, Is.EqualTo(0f));
evaporateTime = evaporation.EvaporateTime;
});
// Wait enough time for it to evaporate if it was unpaused
var sTimeToWait = (5 + (int)Math.Ceiling(amount * evaporateTime * sGameTiming.TickRate));
await server.WaitRunTicks(sTimeToWait);
// No evaporation due to being paused
await server.WaitAssertion(() =>
{
Assert.True(puddle.Owner.Paused);
// Check that the puddle still exists
Assert.False(puddle.Owner.Deleted);
});
// Unpause the map
await server.WaitPost(() => { sPauseManager.SetMapPaused(sMapId, false); });
// Check that the map, grid and puddle are unpaused
await server.WaitAssertion(() =>
{
Assert.False(sPauseManager.IsMapPaused(sMapId));
Assert.False(sPauseManager.IsGridPaused(sGridId));
Assert.False(puddle.Owner.Paused);
// Check that the puddle still exists
Assert.False(puddle.Owner.Deleted);
});
// Wait enough time for it to evaporate
await server.WaitRunTicks(sTimeToWait);
// Puddle evaporation should have ticked
await server.WaitAssertion(() =>
{
// Check that the puddle is unpaused
Assert.False(puddle.Owner.Paused);
// Check that puddle has been deleted
Assert.True(puddle.Deleted);
});
}
}
}