Add new map saving test (#14854)

This commit is contained in:
Leon Friedrich
2023-03-26 14:17:27 +13:00
committed by GitHub
parent dacc9a9d22
commit 1bccbf4013
2 changed files with 76 additions and 5 deletions

View File

@@ -78,6 +78,8 @@ namespace Content.IntegrationTests.Tests
await pairTracker.CleanReturnAsync();
}
const string TestMap = "Maps/bagel.yml";
/// <summary>
/// Loads the default map, runs it for 5 ticks, then assert that it did not change.
/// </summary>
@@ -91,13 +93,13 @@ namespace Content.IntegrationTests.Tests
MapId mapId = default;
// Load saltern.yml as uninitialized map, and save it to ensure it's up to date.
// Load bagel.yml as uninitialized map, and save it to ensure it's up to date.
server.Post(() =>
{
mapId = mapManager.CreateMap();
mapManager.AddUninitializedMap(mapId);
mapManager.SetMapPaused(mapId, true);
mapLoader.LoadMap(mapId, "Maps/bagel.yml");
mapLoader.LoadMap(mapId, TestMap);
mapLoader.SaveMap(mapId, "load save ticks save 1.yml");
});
@@ -145,6 +147,78 @@ namespace Content.IntegrationTests.Tests
TestContext.Error.WriteLine(twoTmp);
}
});
await server.WaitPost(() => mapManager.DeleteMap(mapId));
await pairTracker.CleanReturnAsync();
}
/// <summary>
/// Loads the same uninitialized map at slightly different times, and then checks that they are the same
/// when getting saved.
/// </summary>
/// <remarks>
/// Should ensure that entities do not perform randomization prior to initialization and should prevents
/// bugs like the one discussed in github.com/space-wizards/RobustToolbox/issues/3870. This test is somewhat
/// similar to <see cref="LoadSaveTicksSaveBagel"/> and <see cref="SaveLoadSave"/>, but neither of these
/// caught the mentioned bug.
/// </remarks>
[Test]
public async Task LoadTickLoadBagel()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true});
var server = pairTracker.Pair.Server;
var mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
var mapManager = server.ResolveDependency<IMapManager>();
var userData = server.ResolveDependency<IResourceManager>().UserData;
MapId mapId = default;
const string fileA = "/load tick load a.yml";
const string fileB = "/load tick load b.yml";
string yamlA;
string yamlB;
// Load & save the first map
server.Post(() =>
{
mapId = mapManager.CreateMap();
mapManager.AddUninitializedMap(mapId);
mapManager.SetMapPaused(mapId, true);
mapLoader.LoadMap(mapId, TestMap);
mapLoader.SaveMap(mapId, fileA);
});
await server.WaitIdleAsync();
await using (var stream = userData.Open(new ResourcePath(fileA), FileMode.Open))
using (var reader = new StreamReader(stream))
{
yamlA = await reader.ReadToEndAsync();
}
server.RunTicks(5);
// Load & save the second map
server.Post(() =>
{
mapManager.DeleteMap(mapId);
mapManager.CreateMap(mapId);
mapManager.AddUninitializedMap(mapId);
mapManager.SetMapPaused(mapId, true);
mapLoader.LoadMap(mapId, TestMap);
mapLoader.SaveMap(mapId, fileB);
});
await server.WaitIdleAsync();
await using (var stream = userData.Open(new ResourcePath(fileB), FileMode.Open))
using (var reader = new StreamReader(stream))
{
yamlB = await reader.ReadToEndAsync();
}
Assert.That(yamlA, Is.EqualTo(yamlB));
await server.WaitPost(() => mapManager.DeleteMap(mapId));
await pairTracker.CleanReturnAsync();
}
}