PvsCommandTest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Robust.Shared.GameObjects;
  2. using Robust.Shared.Map.Components;
  3. using Robust.Shared.Prototypes;
  4. namespace Content.IntegrationTests.Tests.Networking;
  5. [TestFixture]
  6. public sealed class PvsCommandTest
  7. {
  8. private static readonly EntProtoId TestEnt = "MobHuman";
  9. [Test]
  10. public async Task TestPvsCommands()
  11. {
  12. await using var pair = await PoolManager.GetServerClient(new PoolSettings { Connected = true, DummyTicker = false });
  13. var (server, client) = pair;
  14. await pair.RunTicksSync(5);
  15. // Spawn a complex entity.
  16. EntityUid entity = default;
  17. await server.WaitPost(() => entity = server.EntMan.Spawn(TestEnt));
  18. await pair.RunTicksSync(5);
  19. // Check that the client has a variety pf entities.
  20. Assert.That(client.EntMan.EntityCount, Is.GreaterThan(0));
  21. Assert.That(client.EntMan.Count<MapComponent>, Is.GreaterThan(0));
  22. Assert.That(client.EntMan.Count<MapGridComponent>, Is.GreaterThan(0));
  23. var meta = client.MetaData(pair.ToClientUid(entity));
  24. var lastApplied = meta.LastStateApplied;
  25. // Dirty all entities
  26. await server.ExecuteCommand("dirty");
  27. await pair.RunTicksSync(5);
  28. Assert.That(meta.LastStateApplied, Is.GreaterThan(lastApplied));
  29. await pair.RunTicksSync(5);
  30. // Do a client-side full state reset
  31. await client.ExecuteCommand("resetallents");
  32. await pair.RunTicksSync(5);
  33. // Request a full server state.
  34. lastApplied = meta.LastStateApplied;
  35. await client.ExecuteCommand("fullstatereset");
  36. await pair.RunTicksSync(10);
  37. Assert.That(meta.LastStateApplied, Is.GreaterThan(lastApplied));
  38. await server.WaitPost(() => server.EntMan.DeleteEntity(entity));
  39. await pair.CleanReturnAsync();
  40. }
  41. }