Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 593bc38

Browse files
author
Jamie Brynes
authored
Fix bug where CommandSender would not reenable after being disabled (#1429)
1 parent bfe5c43 commit 593bc38

File tree

4 files changed

+122
-6
lines changed

4 files changed

+122
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
- Fixed a bug in the Worker Inspector where component foldouts were being rendered too often, causing poor performance when the entity had many components or very complex components. [#1403](https://github.com/spatialos/gdk-for-unity/pull/1403)
3535
- Fixed minor indentation issue in generated code caused by newline formatting. [#1424](https://github.com/spatialos/gdk-for-unity/pull/1424)
36+
- Fixed a bug where `CommandSender` objects would not be made valid again after being _re-injected_. [#1429](https://github.com/spatialos/gdk-for-unity/pull/1429)
3637

3738
### Internal
3839

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using Improbable.Gdk.Core;
2+
using Improbable.Gdk.PlayerLifecycle;
3+
using Improbable.Gdk.Subscriptions;
4+
using Improbable.Gdk.Test;
5+
using Improbable.Gdk.TestUtils;
6+
using Improbable.Worker.CInterop;
7+
using NUnit.Framework;
8+
using UnityEngine;
9+
10+
11+
namespace Improbable.Gdk.EditmodeTests
12+
{
13+
[TestFixture]
14+
public class RequireablesReenableTests : MockBase
15+
{
16+
private const long EntityId = 100;
17+
18+
[Test]
19+
public void CommandSenders_and_Receivers_are_valid_after_reinjection()
20+
{
21+
World
22+
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate()))
23+
.Step(world =>
24+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
25+
.Step(world =>
26+
{
27+
var (_, behaviour) = world.CreateGameObject<CommandSenderReceiverTestBehaviour>(EntityId);
28+
return behaviour;
29+
})
30+
.Step((world, behaviour) =>
31+
{
32+
Assert.IsNotNull(behaviour.CommandReceiver);
33+
Assert.IsNotNull(behaviour.CommandSender);
34+
Assert.IsTrue(behaviour.CommandReceiver.IsValid);
35+
Assert.IsTrue(behaviour.CommandSender.IsValid);
36+
})
37+
.Step(world =>
38+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative))
39+
.Step((world, behaviour) =>
40+
{
41+
Assert.IsNull(behaviour.CommandReceiver);
42+
Assert.IsNull(behaviour.CommandSender);
43+
})
44+
.Step(world =>
45+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
46+
.Step((world, behaviour) =>
47+
{
48+
Assert.IsNotNull(behaviour.CommandReceiver);
49+
Assert.IsNotNull(behaviour.CommandSender);
50+
Assert.IsTrue(behaviour.CommandReceiver.IsValid);
51+
Assert.IsTrue(behaviour.CommandSender.IsValid);
52+
});
53+
}
54+
55+
[Test]
56+
public void Readers_and_Writers_are_valid_after_reinjection()
57+
{
58+
World
59+
.Step(world => world.Connection.CreateEntity(EntityId, GetTemplate()))
60+
.Step(world =>
61+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
62+
.Step(world =>
63+
{
64+
var (_, behaviour) = world.CreateGameObject<ReaderWriterTestBehaviour>(EntityId);
65+
return behaviour;
66+
})
67+
.Step((world, behaviour) =>
68+
{
69+
Assert.IsNotNull(behaviour.Writer);
70+
Assert.IsNotNull(behaviour.Reader);
71+
Assert.IsTrue(behaviour.Writer.IsValid);
72+
Assert.IsTrue(behaviour.Reader.IsValid);
73+
})
74+
.Step(world =>
75+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.NotAuthoritative))
76+
.Step((world, behaviour) =>
77+
{
78+
Assert.IsNull(behaviour.Writer);
79+
Assert.IsNull(behaviour.Reader);
80+
})
81+
.Step(world =>
82+
world.Connection.ChangeAuthority(EntityId, TestCommands.ComponentId, Authority.Authoritative))
83+
.Step((world, behaviour) =>
84+
{
85+
Assert.IsNotNull(behaviour.Writer);
86+
Assert.IsNotNull(behaviour.Reader);
87+
Assert.IsTrue(behaviour.Writer.IsValid);
88+
Assert.IsTrue(behaviour.Reader.IsValid);
89+
});
90+
}
91+
92+
private static EntityTemplate GetTemplate()
93+
{
94+
var template = new EntityTemplate();
95+
template.AddComponent(new Position.Snapshot(), "worker");
96+
template.AddComponent(new TestCommands.Snapshot(), "worker");
97+
return template;
98+
}
99+
100+
private class CommandSenderReceiverTestBehaviour : MonoBehaviour
101+
{
102+
#pragma warning disable 649
103+
[Require] public TestCommandsCommandReceiver CommandReceiver;
104+
[Require] public PlayerHeartbeatClientCommandSender CommandSender;
105+
#pragma warning restore 649
106+
}
107+
108+
private class ReaderWriterTestBehaviour : MonoBehaviour
109+
{
110+
#pragma warning disable 649
111+
[Require] public TestCommandsWriter Writer;
112+
[Require] public TestCommandsReader Reader;
113+
#pragma warning restore 649
114+
}
115+
}
116+
}

workers/unity/Assets/Tests/EditmodeTests/Correctness/Subscriptions/RequireablesReenableTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Packages/io.improbable.gdk.core/Subscriptions/CommandSenderReceiverSubscriptionManagerBase.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77

88
namespace Improbable.Gdk.Subscriptions
99
{
10-
public interface ICommandSender
10+
public interface ICommandSender : IRequireable
1111
{
12-
bool IsValid { get; set; }
13-
void RemoveAllCallbacks();
1412
}
1513

16-
public interface ICommandReceiver
14+
public interface ICommandReceiver : IRequireable
1715
{
18-
bool IsValid { get; set; }
19-
void RemoveAllCallbacks();
2016
}
2117

2218
public abstract class CommandSenderSubscriptionManagerBase<T> : SubscriptionManager<T>

0 commit comments

Comments
 (0)