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
Fix bug where CommandSender would not reenable after being disabled #1429
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57f1b19
fix bug where command senders would not re-enable after being disabled
jamiebrynes7 db95b3c
test cases
jamiebrynes7 5544580
changelog
jamiebrynes7 bd71441
name tweaks
jamiebrynes7 9324e8f
suppress unassigned warnings
jamiebrynes7 abc0bee
unused usings
jamiebrynes7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
117 changes: 117 additions & 0 deletions
117
...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,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Improbable.Gdk.Core; | ||
using Improbable.Gdk.Core.Commands; | ||
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; | ||
using UnityEngine.TestTools; | ||
using Empty = Improbable.Gdk.Core.Empty; | ||
using Entity = Unity.Entities.Entity; | ||
|
||
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<CommandSenderTestBehaviour>(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<ReaderTestBehaviour>(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 CommandSenderTestBehaviour : MonoBehaviour | ||
{ | ||
[Require] public TestCommandsCommandReceiver CommandReceiver; | ||
[Require] public PlayerHeartbeatClientCommandSender CommandSender; | ||
} | ||
|
||
private class ReaderTestBehaviour : MonoBehaviour | ||
jamiebrynes7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
[Require] public TestCommandsWriter Writer; | ||
[Require] public TestCommandsReader Reader; | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this check if the captured command sender/receiver is invalidated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are captured in https://github.com/spatialos/gdk-for-unity/blob/develop/workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/RequireablesDisableTests.cs :)