fix benchmark
improve some test diagnostics fix some bug where order of shutdown of AiControllerComponent mattered or Processor was never initialized
This commit is contained in:
@@ -2,9 +2,13 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Moq;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Log;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
|
||||
namespace Content.Benchmarks
|
||||
{
|
||||
@@ -14,7 +18,17 @@ namespace Content.Benchmarks
|
||||
|
||||
private IComponentManager _componentManager;
|
||||
|
||||
[Params(500, 1000, 5000)] public int N { get; set; }
|
||||
[Params(5000)] public int N { get; set; }
|
||||
|
||||
public static void TestRun()
|
||||
{
|
||||
var x = new ComponentManagerGetAllComponents
|
||||
{
|
||||
N = 500
|
||||
};
|
||||
x.Setup();
|
||||
x.Run();
|
||||
}
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
@@ -23,6 +37,13 @@ namespace Content.Benchmarks
|
||||
IoCManager.InitThread();
|
||||
|
||||
IoCManager.Register<IComponentManager, ComponentManager>();
|
||||
IoCManager.Register<IRuntimeLog, RuntimeLog>();
|
||||
IoCManager.Register<ILogManager, LogManager>();
|
||||
IoCManager.Register<IDynamicTypeFactory, DynamicTypeFactory>();
|
||||
IoCManager.Register<IEntitySystemManager, EntitySystemManager>();
|
||||
var entityManager = new Mock<IEntityManager>().Object;
|
||||
IoCManager.RegisterInstance<IEntityManager>(entityManager);
|
||||
IoCManager.RegisterInstance<IReflectionManager>(new Mock<IReflectionManager>().Object);
|
||||
|
||||
var dummyReg = new Mock<IComponentRegistration>();
|
||||
dummyReg.SetupGet(p => p.Name).Returns("Dummy");
|
||||
@@ -34,17 +55,19 @@ namespace Content.Benchmarks
|
||||
var componentFactory = new Mock<IComponentFactory>();
|
||||
componentFactory.Setup(p => p.GetComponent<DummyComponent>()).Returns(new DummyComponent());
|
||||
componentFactory.Setup(p => p.GetRegistration(It.IsAny<DummyComponent>())).Returns(dummyReg.Object);
|
||||
componentFactory.Setup(p => p.GetAllRefTypes()).Returns(new[] {typeof(DummyComponent)});
|
||||
|
||||
IoCManager.RegisterInstance<IComponentFactory>(componentFactory.Object);
|
||||
|
||||
IoCManager.BuildGraph();
|
||||
|
||||
_componentManager = IoCManager.Resolve<IComponentManager>();
|
||||
_componentManager.Initialize();
|
||||
|
||||
// Initialize N entities with one component.
|
||||
for (var i = 0; i < N; i++)
|
||||
{
|
||||
var entity = new Entity();
|
||||
entity.SetManagers(entityManager);
|
||||
entity.SetUid(new EntityUid(i + 1));
|
||||
_entities.Add(entity);
|
||||
|
||||
@@ -65,6 +88,16 @@ namespace Content.Benchmarks
|
||||
return count;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int Noop()
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
_componentManager.TryGetComponent(default, out DummyComponent _);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private class DummyComponent : Component
|
||||
{
|
||||
public override string Name => "Dummy";
|
||||
|
||||
@@ -6,7 +6,8 @@ namespace Content.Benchmarks
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BenchmarkRunner.Run<StereoToMonoBenchmark>();
|
||||
BenchmarkRunner.Run<ComponentManagerGetAllComponents>();
|
||||
//ComponentManagerGetAllComponents.TestRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ namespace Content.IntegrationTests.Tests
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogS(LogLevel.Error, "EntityTest", "Entity '" + prototype.ID + "' threw: " + e.Message);
|
||||
Assert.Fail();
|
||||
//Assert.Fail();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Interfaces.Maps;
|
||||
@@ -37,19 +38,34 @@ namespace Content.IntegrationTests.Tests
|
||||
string one;
|
||||
string two;
|
||||
|
||||
using (var stream = userData.Open(new ResourcePath("save load save 1.yml"), FileMode.Open))
|
||||
var rp1 = new ResourcePath("save load save 1.yml");
|
||||
using (var stream = userData.Open(rp1, FileMode.Open))
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
one = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
using (var stream = userData.Open(new ResourcePath("save load save 2.yml"), FileMode.Open))
|
||||
var rp2 = new ResourcePath("save load save 2.yml");
|
||||
using (var stream = userData.Open(rp2, FileMode.Open))
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
two = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
Assert.Multiple(() => {
|
||||
Assert.That(one, Is.EqualTo(two));
|
||||
var failed = TestContext.CurrentContext.Result.Assertions.FirstOrDefault();
|
||||
if (failed != null)
|
||||
{
|
||||
var path1 = Path.Combine(userData.RootDir!,rp1.ToRelativeSystemPath());
|
||||
var path2 = Path.Combine(userData.RootDir!,rp2.ToRelativeSystemPath());
|
||||
TestContext.AddTestAttachment(path1);
|
||||
TestContext.AddTestAttachment(path2);
|
||||
TestContext.Error.WriteLine("Complete output:");
|
||||
TestContext.Error.WriteLine(path1);
|
||||
TestContext.Error.WriteLine(path2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Content.Server.GameObjects
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref StorageCapacityMax, "Capacity", 10000);
|
||||
serializer.DataField(ref StorageUsed, "used", 0);
|
||||
//serializer.DataField(ref StorageUsed, "used", 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -348,7 +348,7 @@ namespace Content.Server.GameObjects
|
||||
|
||||
foreach (var entity in storage.ContainedEntities)
|
||||
{
|
||||
var item = entity.GetComponent<ItemComponent>();
|
||||
var item = entity.GetComponent<StoreableComponent>();
|
||||
StorageUsed += item.ObjectSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
protected override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
Processor.Shutdown();
|
||||
Processor?.Shutdown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user