Remove AllComponentsOneEntityDeleteTest (#19965)

* Remove AllComponentsOneEntityDeleteTest

* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
This commit is contained in:
Leon Friedrich
2023-09-10 12:35:05 +12:00
committed by GitHub
parent 41b0b0ac64
commit 2d71eec6f9
10 changed files with 13 additions and 144 deletions

View File

@@ -208,6 +208,7 @@ namespace Content.IntegrationTests.Tests
"GridFillComponent", "GridFillComponent",
"Map", // We aren't testing a map entity in this test "Map", // We aren't testing a map entity in this test
"MapGrid", "MapGrid",
"Broadphase",
"StationData", // errors when removed mid-round "StationData", // errors when removed mid-round
"Actor", // We aren't testing actor components, those need their player session set. "Actor", // We aren't testing actor components, those need their player session set.
"BlobFloorPlanBuilder", // Implodes if unconfigured. "BlobFloorPlanBuilder", // Implodes if unconfigured.
@@ -292,136 +293,5 @@ namespace Content.IntegrationTests.Tests
await pair.CleanReturnAsync(); await pair.CleanReturnAsync();
} }
[Test]
public async Task AllComponentsOneEntityDeleteTest()
{
var skipComponents = new[]
{
"DebugExceptionOnAdd", // Debug components that explicitly throw exceptions
"DebugExceptionExposeData",
"DebugExceptionInitialize",
"DebugExceptionStartup",
"GridFillComponent",
"Map", // We aren't testing a map entity in this test
"MapGrid",
"StationData", // errors when deleted mid-round
"Actor", // We aren't testing actor components, those need their player session set.
"BlobFloorPlanBuilder", // Implodes if unconfigured.
"DebrisFeaturePlacerController", // Above.
"LoadedChunk", // Worldgen chunk loading malding.
"BiomeSelection", // Whaddya know, requires config.
"DeployableBarrier",
};
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var componentFactory = server.ResolveDependency<IComponentFactory>();
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
var logmill = server.ResolveDependency<ILogManager>().GetSawmill("EntityTest");
MapGridComponent grid = default;
await server.WaitPost(() =>
{
// Create a one tile grid to stave off the grid 0 monsters
var mapId = mapManager.CreateMap();
mapManager.AddUninitializedMap(mapId);
grid = mapManager.CreateGrid(mapId);
var tileDefinition = tileDefinitionManager["Plating"];
var tile = new Tile(tileDefinition.TileId);
grid.SetTile(Vector2i.Zero, tile);
mapManager.DoMapInitialize(mapId);
});
await server.WaitRunTicks(5);
var distinctComponents = new List<(List<CompIdx> components, List<CompIdx> references)>
{
(new List<CompIdx>(), new List<CompIdx>())
};
// Split components into groups, ensuring that their references don't conflict
foreach (var type in componentFactory.AllRegisteredTypes)
{
var registration = componentFactory.GetRegistration(type);
for (var i = 0; i < distinctComponents.Count; i++)
{
var (components, references) = distinctComponents[i];
if (references.Intersect(registration.References).Any())
{
// Ensure the next list if this one has conflicting references
if (i + 1 >= distinctComponents.Count)
{
distinctComponents.Add((new List<CompIdx>(), new List<CompIdx>()));
}
continue;
}
// Add the component and its references if no conflicting references were found
components.Add(registration.Idx);
references.AddRange(registration.References);
}
}
// Sanity check
Assert.That(distinctComponents, Is.Not.Empty);
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
foreach (var (components, _) in distinctComponents)
{
var testLocation = grid.ToCoordinates();
var entity = entityManager.SpawnEntity(null, testLocation);
Assert.That(entityManager.GetComponent<MetaDataComponent>(entity).EntityInitialized);
foreach (var type in components)
{
var component = (Component) componentFactory.GetComponent(type);
// If the entity already has this component, if it was ensured or added by another
if (entityManager.HasComponent(entity, component.GetType()))
{
continue;
}
var name = componentFactory.GetComponentName(component.GetType());
// If this component is ignored
if (skipComponents.Contains(name))
continue;
component.Owner = entity;
logmill.Debug($"Adding component: {name}");
// Note for the future coder: if an exception occurs where a component reference
// was already occupied it might be because some component is ensuring another // initialize.
// If so, search for cases of EnsureComponent<FailingType>, EnsureComponentWarn<FailingType>
// and all others variations (out parameter)
Assert.DoesNotThrow(() =>
{
entityManager.AddComponent(entity, component);
}, "Component '{0}' threw an exception.",
name);
}
entityManager.DeleteEntity(entity);
}
});
});
await pair.CleanReturnAsync();
}
} }
} }

View File

@@ -20,5 +20,5 @@ public sealed partial class RandomFillSolutionComponent : Component
/// Weighted random fill prototype Id. Used to pick reagent and quantity. /// Weighted random fill prototype Id. Used to pick reagent and quantity.
/// </summary> /// </summary>
[DataField("weightedRandomId", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomFillSolutionPrototype>))] [DataField("weightedRandomId", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomFillSolutionPrototype>))]
public string WeightedRandomId { get; set; } = "default"; public string? WeightedRandomId;
} }

View File

@@ -22,6 +22,9 @@ public sealed class SolutionRandomFillSystem : EntitySystem
private void OnRandomSolutionFillMapInit(EntityUid uid, RandomFillSolutionComponent component, MapInitEvent args) private void OnRandomSolutionFillMapInit(EntityUid uid, RandomFillSolutionComponent component, MapInitEvent args)
{ {
if (component.WeightedRandomId == null)
return;
var target = _solutionsSystem.EnsureSolution(uid, component.Solution); var target = _solutionsSystem.EnsureSolution(uid, component.Solution);
var pick = _proto.Index<WeightedRandomFillSolutionPrototype>(component.WeightedRandomId).Pick(_random); var pick = _proto.Index<WeightedRandomFillSolutionPrototype>(component.WeightedRandomId).Pick(_random);

View File

@@ -12,5 +12,5 @@ namespace Content.Server.Humanoid.Components;
public sealed partial class RandomHumanoidSpawnerComponent : Component public sealed partial class RandomHumanoidSpawnerComponent : Component
{ {
[DataField("settings", customTypeSerializer: typeof(PrototypeIdSerializer<RandomHumanoidSettingsPrototype>))] [DataField("settings", customTypeSerializer: typeof(PrototypeIdSerializer<RandomHumanoidSettingsPrototype>))]
public string SettingsPrototypeId = default!; public string? SettingsPrototypeId;
} }

View File

@@ -29,6 +29,7 @@ public sealed class RandomHumanoidSystem : EntitySystem
private void OnMapInit(EntityUid uid, RandomHumanoidSpawnerComponent component, MapInitEvent args) private void OnMapInit(EntityUid uid, RandomHumanoidSpawnerComponent component, MapInitEvent args)
{ {
QueueDel(uid); QueueDel(uid);
if (component.SettingsPrototypeId != null)
SpawnRandomHumanoid(component.SettingsPrototypeId, Transform(uid).Coordinates, MetaData(uid).EntityName); SpawnRandomHumanoid(component.SettingsPrototypeId, Transform(uid).Coordinates, MetaData(uid).EntityName);
} }

View File

@@ -246,7 +246,7 @@ namespace Content.Server.Light.EntitySystems
ApcPowerReceiverComponent? powerReceiver = null, ApcPowerReceiverComponent? powerReceiver = null,
AppearanceComponent? appearance = null) AppearanceComponent? appearance = null)
{ {
if (!Resolve(uid, ref light, ref powerReceiver)) if (!Resolve(uid, ref light, ref powerReceiver, false))
return; return;
// Optional component. // Optional component.

View File

@@ -120,7 +120,7 @@ public sealed class ApcSystem : EntitySystem
ApcComponent? apc=null, ApcComponent? apc=null,
PowerNetworkBatteryComponent? battery = null) PowerNetworkBatteryComponent? battery = null)
{ {
if (!Resolve(uid, ref apc, ref battery)) if (!Resolve(uid, ref apc, ref battery, false))
return; return;
var newState = CalcChargeState(uid, battery.NetworkBattery); var newState = CalcChargeState(uid, battery.NetworkBattery);

View File

@@ -57,7 +57,7 @@ internal sealed class SmesSystem : EntitySystem
private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null) private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null)
{ {
if (!Resolve(uid, ref battery)) if (!Resolve(uid, ref battery, false))
return 0; return 0;
return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6); return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6);
@@ -65,7 +65,7 @@ internal sealed class SmesSystem : EntitySystem
private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null) private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null)
{ {
if (!Resolve(uid, ref netBattery)) if (!Resolve(uid, ref netBattery, false))
return ChargeState.Still; return ChargeState.Still;
return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch

View File

@@ -172,10 +172,8 @@ namespace Content.Server.Solar.EntitySystems
SolarPanelComponent? solar = null, SolarPanelComponent? solar = null,
PowerSupplierComponent? supplier = null) PowerSupplierComponent? supplier = null)
{ {
if (!Resolve(uid, ref solar, ref supplier)) if (!Resolve(uid, ref solar, ref supplier, false))
{
return; return;
}
supplier.MaxSupply = (int) (solar.MaxSupply * solar.Coverage); supplier.MaxSupply = (int) (solar.MaxSupply * solar.Coverage);
} }

View File

@@ -17,10 +17,7 @@ public sealed class ContainerFillSystem : EntitySystem
private void OnMapInit(EntityUid uid, ContainerFillComponent component, MapInitEvent args) private void OnMapInit(EntityUid uid, ContainerFillComponent component, MapInitEvent args)
{ {
if (!TryComp(uid, out ContainerManagerComponent? containerComp)) if (!TryComp(uid, out ContainerManagerComponent? containerComp))
{
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} has no {nameof(ContainerManagerComponent)}.");
return; return;
}
var xform = Transform(uid); var xform = Transform(uid);
var coords = new EntityCoordinates(uid, Vector2.Zero); var coords = new EntityCoordinates(uid, Vector2.Zero);