mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Isolate net messages in integration tests. Integration tests don't use Lidgren to connect client and send, instead they just use some in-process channels to communicate. Because of this, the original implementation of net messages *directly* passed the net message instances between client and server instances. This caused issues whenever content would mutate data in a NetMessage after it "passed through". Now we run the messages through WriteToBuffer() and ReadFromBuffer() so they pass through binary serialization. This means there's no more implicit sharing of the objects. Note that this requires some trickery: Lidgren's message types have internal constructors. Really ideally we'd change the engine to make this more testable... but that's a content breaking change. Instead I just added InternalsVisibleTo to Lidgren so we can mess with it. We maintain the library ourselves anyways I can do what I want. Fixes #4836 * Register Robust.UnitTesting as assembly for reflection. This is necessary so that serialized types in the assembly can be picked up by NetSerializer. Have to disable automatic reflection on all entity systems/components that tests register manually right now, because otherwise tests break. * Stop shallow cloning specific net messages in integration tests. This isn't necessary anymore now that we have a thorough fix. * Wow I really forgot to copy-paste that line to the other side huh. * Add test that serializer hash matches. * Another test one I missed earlier. * Changelog
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.UnitTesting.Shared;
|
|
|
|
[Parallelizable(ParallelScope.All)]
|
|
internal sealed class TestRobustSerializerHash : RobustIntegrationTest
|
|
{
|
|
/// <summary>
|
|
/// Test that the serializer hash on client and server matches.
|
|
/// </summary>
|
|
[Test]
|
|
public async Task Test()
|
|
{
|
|
var server = StartServer();
|
|
var client = StartClient();
|
|
|
|
var manifestServerStream = new MemoryStream();
|
|
var manifestClientStream = new MemoryStream();
|
|
|
|
await server.WaitPost(() =>
|
|
{
|
|
var serializer = (RobustSerializer) IoCManager.Resolve<IRobustSerializer>();
|
|
serializer.GetHashManifest(manifestServerStream, writeNewline: true);
|
|
});
|
|
|
|
await client.WaitPost(() =>
|
|
{
|
|
var serializer = (RobustSerializer) IoCManager.Resolve<IRobustSerializer>();
|
|
serializer.GetHashManifest(manifestClientStream, writeNewline: true);
|
|
});
|
|
|
|
var manifestServer = Encoding.UTF8.GetString(manifestServerStream.AsSpan());
|
|
var manifestClient = Encoding.UTF8.GetString(manifestClientStream.AsSpan());
|
|
|
|
Assert.That(manifestServer, NUnit.Framework.Is.EqualTo(manifestClient));
|
|
}
|
|
}
|