Make tests faster (#8737)

* Test changes

* Make finding the test tile a little smarter
This commit is contained in:
wrexbe
2022-06-19 20:22:28 -07:00
committed by GitHub
parent bd54b8de25
commit 81e3b2da88
80 changed files with 1769 additions and 1788 deletions

View File

@@ -3,8 +3,6 @@ using System.Threading.Tasks;
using Content.Server.Storage.Components;
using NUnit.Framework;
using Robust.Client.GameObjects;
using Robust.Server.Player;
using Robust.Shared;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
@@ -12,9 +10,9 @@ using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests
{
public sealed class ContainerOcclusionTest : ContentIntegrationTest
public sealed class ContainerOcclusionTest
{
private const string ExtraPrototypes = @"
private const string Prototypes = @"
- type: entity
id: ContainerOcclusionA
components:
@@ -35,53 +33,21 @@ namespace Content.IntegrationTests.Tests
- type: PointLight
";
private async Task<(ClientIntegrationInstance c, ServerIntegrationInstance s)> Start()
{
var optsServer = new ServerIntegrationOptions
{
CVarOverrides =
{
{CVars.NetPVS.Name, "false"}
},
ExtraPrototypes = ExtraPrototypes
};
var optsClient = new ClientIntegrationOptions
{
CVarOverrides =
{
{CVars.NetPVS.Name, "false"}
},
ExtraPrototypes = ExtraPrototypes
};
var (c, s) = await StartConnectedServerDummyTickerClientPair(optsClient, optsServer);
s.Post(() =>
{
IoCManager.Resolve<IPlayerManager>().ServerSessions.Single().JoinGame();
var mapMan = IoCManager.Resolve<IMapManager>();
mapMan.CreateMap(new MapId(1));
});
return (c, s);
}
[Test]
public async Task TestA()
{
var (c, s) = await Start();
await c.WaitIdleAsync();
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{ExtraPrototypes = Prototypes});
var s = pairTracker.Pair.Server;
var c = pairTracker.Pair.Client;
var cEntities = c.ResolveDependency<IEntityManager>();
EntityUid dummy = default;
s.Post(() =>
var ent2 = s.ResolveDependency<IMapManager>();
await s.WaitPost(() =>
{
var pos = new MapCoordinates(Vector2.Zero, new MapId(1));
var mapId = ent2.GetAllMapIds().Last();
var pos = new MapCoordinates(Vector2.Zero, mapId);
var ent = IoCManager.Resolve<IEntityManager>();
var container = ent.SpawnEntity("ContainerOcclusionA", pos);
dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos);
@@ -89,9 +55,9 @@ namespace Content.IntegrationTests.Tests
ent.GetComponent<EntityStorageComponent>(container).Insert(dummy);
});
await RunTicksSync(c, s, 5);
await PoolManager.RunTicksSync(pairTracker.Pair, 5);
c.Assert(() =>
await c.WaitAssertion(() =>
{
var sprite = cEntities.GetComponent<SpriteComponent>(dummy);
var light = cEntities.GetComponent<PointLightComponent>(dummy);
@@ -99,22 +65,24 @@ namespace Content.IntegrationTests.Tests
Assert.True(light.ContainerOccluded);
});
await Task.WhenAll(c.WaitIdleAsync(), s.WaitIdleAsync());
await pairTracker.CleanReturnAsync();
}
[Test]
public async Task TestB()
{
var (c, s) = await Start();
await c.WaitIdleAsync();
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{ExtraPrototypes = Prototypes});
var s = pairTracker.Pair.Server;
var c = pairTracker.Pair.Client;
var cEntities = c.ResolveDependency<IEntityManager>();
var ent2 = s.ResolveDependency<IMapManager>();
EntityUid dummy = default;
s.Post(() =>
await s.WaitPost(() =>
{
var pos = new MapCoordinates(Vector2.Zero, new MapId(1));
var mapId = ent2.GetAllMapIds().Last();
var pos = new MapCoordinates(Vector2.Zero, mapId);
var ent = IoCManager.Resolve<IEntityManager>();
var container = ent.SpawnEntity("ContainerOcclusionB", pos);
dummy = ent.SpawnEntity("ContainerOcclusionDummy", pos);
@@ -122,9 +90,9 @@ namespace Content.IntegrationTests.Tests
ent.GetComponent<EntityStorageComponent>(container).Insert(dummy);
});
await RunTicksSync(c, s, 5);
await PoolManager.RunTicksSync(pairTracker.Pair, 5);
c.Assert(() =>
await c.WaitAssertion(() =>
{
var sprite = cEntities.GetComponent<SpriteComponent>(dummy);
var light = cEntities.GetComponent<PointLightComponent>(dummy);
@@ -132,22 +100,24 @@ namespace Content.IntegrationTests.Tests
Assert.False(light.ContainerOccluded);
});
await Task.WhenAll(c.WaitIdleAsync(), s.WaitIdleAsync());
await pairTracker.CleanReturnAsync();
}
[Test]
public async Task TestAb()
{
var (c, s) = await Start();
await c.WaitIdleAsync();
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{ExtraPrototypes = Prototypes});
var s = pairTracker.Pair.Server;
var c = pairTracker.Pair.Client;
var ent2 = s.ResolveDependency<IMapManager>();
var cEntities = c.ResolveDependency<IEntityManager>();
EntityUid dummy = default;
s.Post(() =>
await s.WaitPost(() =>
{
var pos = new MapCoordinates(Vector2.Zero, new MapId(1));
var mapId = ent2.GetAllMapIds().Last();
var pos = new MapCoordinates(Vector2.Zero, mapId);
var ent = IoCManager.Resolve<IEntityManager>();
var containerA = ent.SpawnEntity("ContainerOcclusionA", pos);
var containerB = ent.SpawnEntity("ContainerOcclusionB", pos);
@@ -157,9 +127,9 @@ namespace Content.IntegrationTests.Tests
ent.GetComponent<EntityStorageComponent>(containerB).Insert(dummy);
});
await RunTicksSync(c, s, 5);
await PoolManager.RunTicksSync(pairTracker.Pair, 5);
c.Assert(() =>
await c.WaitAssertion(() =>
{
var sprite = cEntities.GetComponent<SpriteComponent>(dummy);
var light = cEntities.GetComponent<PointLightComponent>(dummy);
@@ -167,7 +137,7 @@ namespace Content.IntegrationTests.Tests
Assert.True(light.ContainerOccluded);
});
await Task.WhenAll(c.WaitIdleAsync(), s.WaitIdleAsync());
await pairTracker.CleanReturnAsync();
}
}
}