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 bug where CommandSender would not reenable after being disabled (#…
- Loading branch information
Jamie Brynes
authored
Jul 17, 2020
1 parent
bfe5c43
commit 593bc38
Showing
4 changed files
with
122 additions
and
6 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
116 changes: 116 additions & 0 deletions
116
...s/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/RequireablesReenableTests.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,116 @@ | ||
using Improbable.Gdk.Core; | ||
using Improbable.Gdk.PlayerLifecycle; | ||
using Improbable.Gdk.Subscriptions; | ||
using Improbable.Gdk.Test; | ||
using Improbable.Gdk.TestUtils; | ||
using Improbable.Worker.CInterop; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
|
||
|
||
namespace Improbable.Gdk.EditmodeTests | ||
{ | ||
[TestFixture] | ||
public class RequireablesReenableTests : MockBase | ||
{ | ||
private const long EntityId = 100; | ||
|
||
[Test] | ||
public void CommandSenders_and_Receivers_are_valid_after_reinjection() | ||
{ | ||
World | ||
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative)) | ||
.Step(world => | ||
{ | ||
var (_, behaviour) = world.CreateGameObject<CommandSenderReceiverTestBehaviour>(EntityId); | ||
return behaviour; | ||
}) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNotNull(behaviour.CommandReceiver); | ||
Assert.IsNotNull(behaviour.CommandSender); | ||
Assert.IsTrue(behaviour.CommandReceiver.IsValid); | ||
Assert.IsTrue(behaviour.CommandSender.IsValid); | ||
}) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative)) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNull(behaviour.CommandReceiver); | ||
Assert.IsNull(behaviour.CommandSender); | ||
}) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative)) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNotNull(behaviour.CommandReceiver); | ||
Assert.IsNotNull(behaviour.CommandSender); | ||
Assert.IsTrue(behaviour.CommandReceiver.IsValid); | ||
Assert.IsTrue(behaviour.CommandSender.IsValid); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void Readers_and_Writers_are_valid_after_reinjection() | ||
{ | ||
World | ||
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate())) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative)) | ||
.Step(world => | ||
{ | ||
var (_, behaviour) = world.CreateGameObject<ReaderWriterTestBehaviour>(EntityId); | ||
return behaviour; | ||
}) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNotNull(behaviour.Writer); | ||
Assert.IsNotNull(behaviour.Reader); | ||
Assert.IsTrue(behaviour.Writer.IsValid); | ||
Assert.IsTrue(behaviour.Reader.IsValid); | ||
}) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative)) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNull(behaviour.Writer); | ||
Assert.IsNull(behaviour.Reader); | ||
}) | ||
.Step(world => | ||
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative)) | ||
.Step((world, behaviour) => | ||
{ | ||
Assert.IsNotNull(behaviour.Writer); | ||
Assert.IsNotNull(behaviour.Reader); | ||
Assert.IsTrue(behaviour.Writer.IsValid); | ||
Assert.IsTrue(behaviour.Reader.IsValid); | ||
}); | ||
} | ||
|
||
private static EntityTemplate GetTemplate() | ||
{ | ||
var template = new EntityTemplate(); | ||
template.AddComponent(new Position.Snapshot(), "worker"); | ||
template.AddComponent(new TestCommands.Snapshot(), "worker"); | ||
return template; | ||
} | ||
|
||
private class CommandSenderReceiverTestBehaviour : MonoBehaviour | ||
{ | ||
#pragma warning disable 649 | ||
[Require] public TestCommandsCommandReceiver CommandReceiver; | ||
[Require] public PlayerHeartbeatClientCommandSender CommandSender; | ||
#pragma warning restore 649 | ||
} | ||
|
||
private class ReaderWriterTestBehaviour : MonoBehaviour | ||
{ | ||
#pragma warning disable 649 | ||
[Require] public TestCommandsWriter Writer; | ||
[Require] public TestCommandsReader Reader; | ||
#pragma warning restore 649 | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ty/Assets/Tests/EditmodeTests/Correctness/Subscriptions/RequireablesReenableTests.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