This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix authority changes ordering problem (#1465)
- Loading branch information
Jamie Brynes
authored
Aug 27, 2020
1 parent
03f85ef
commit a073a24
Showing
10 changed files
with
108 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
workers/unity/Assets/Tests/EditmodeTests/Correctness/Core/OpOrderingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Improbable.Gdk.Core; | ||
using Improbable.Gdk.Test; | ||
using Improbable.Gdk.TestUtils; | ||
using Improbable.Worker.CInterop; | ||
using NUnit.Framework; | ||
|
||
namespace Improbable.Gdk.EditmodeTests | ||
{ | ||
[TestFixture] | ||
public class Test : MockBase | ||
{ | ||
private const long EntityId = 1; | ||
|
||
[Test] | ||
public void Authority_changes_are_kept_in_order_and_applied_in_order() | ||
{ | ||
World | ||
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) | ||
.Step(world => | ||
{ | ||
world.Connection.ChangeAuthority(EntityId, 54, Authority.Authoritative); | ||
world.Connection.ChangeAuthority(EntityId, 54, Authority.NotAuthoritative); | ||
}) | ||
.Step(world => | ||
{ | ||
var authChanges = world | ||
.GetSystem<ComponentUpdateSystem>() | ||
.GetAuthorityChangesReceived(new EntityId(EntityId), 54); | ||
|
||
Assert.AreEqual(2, authChanges.Count); | ||
Assert.AreEqual(Authority.Authoritative, authChanges[0].Authority); | ||
Assert.AreEqual(Authority.NotAuthoritative, authChanges[1].Authority); | ||
|
||
var ecsEntity = world.GetSystem<WorkerSystem>().GetEntity(new EntityId(EntityId)); | ||
|
||
Assert.IsFalse(world.Worker.World.EntityManager.HasComponent<Position.HasAuthority>(ecsEntity)); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void Component_updates_are_kept_in_order() | ||
{ | ||
World | ||
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) | ||
.Step(world => | ||
{ | ||
world.Connection.UpdateComponent(EntityId, 54, new Position.Update | ||
{ | ||
Coords = new Coordinates(1, 0, 0) | ||
}); | ||
world.Connection.UpdateComponent(EntityId, 54, new Position.Update | ||
{ | ||
Coords = new Coordinates(-1, 0, 0) | ||
}); | ||
}) | ||
.Step(world => | ||
{ | ||
var componentUpdates = world | ||
.GetSystem<ComponentUpdateSystem>() | ||
.GetComponentUpdatesReceived<Position.Update>(); | ||
|
||
Assert.AreEqual(2, componentUpdates.Count); | ||
Assert.AreEqual(1, componentUpdates[0].Update.Coords.Value.X); | ||
Assert.AreEqual(-1, componentUpdates[1].Update.Coords.Value.X); | ||
|
||
var ecsEntity = world.GetSystem<WorkerSystem>().GetEntity(new EntityId(EntityId)); | ||
|
||
Assert.AreEqual(-1, world.Worker.World.EntityManager.GetComponentData<Position.Component>(ecsEntity).Coords.X); | ||
}); | ||
} | ||
|
||
private static EntityTemplate GetTemplate() | ||
{ | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot()); | ||
return template; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
workers/unity/Assets/Tests/EditmodeTests/Correctness/Core/OpOrderingTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters