]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add new map saving test (#14854)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Sun, 26 Mar 2023 01:17:27 +0000 (14:17 +1300)
committerGitHub <noreply@github.com>
Sun, 26 Mar 2023 01:17:27 +0000 (12:17 +1100)
Content.IntegrationTests/Tests/SaveLoadSaveTest.cs
Resources/Maps/bagel.yml

index 85b95ef1177659560c6df9e743dab13ca2fbde6b..c85ca1952a801a339eedc82b4c10ef4a479beee5 100644 (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();
         }
     }
index 28768d89b93f4c58f7a45967e90a81af8ec31a8c..71f31e9914098a8cd87c640f3b9640f5a84545e1 100644 (file)
@@ -9373,9 +9373,6 @@ entities:
   - nextUpdate: 8187.135845\r
     type: GridPathfinding\r
   - type: RadiationGridResistance\r
-  - nextShake: 0\r
-    shakeTimes: 10\r
-    type: GravityShake\r
   - type: GasTileOverlay\r
 - uid: 61\r
   type: GasVentScrubber\r