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

Fix Readers not re-validating with AggregateSubscription #1326

Merged
merged 8 commits into from
Mar 20, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Improbable.Gdk.Subscriptions;
using Improbable.Gdk.Test;
using Improbable.Gdk.TestUtils;
using Improbable.Tests;
using Improbable.Worker.CInterop;
using NUnit.Framework;
using UnityEngine;
Expand Down Expand Up @@ -38,6 +39,66 @@ public void Reader_is_disabled_if_component_removed()
});
}

[Test]
public void Reader_is_reenabled_if_component_regained()
{
World
.Step(world =>
{
world.Connection.CreateEntity(EntityId, GetTemplate());
})
.Step(world =>
{
var (_, readerBehaviour) = world.CreateGameObject<PositionReaderBehaviour>(EntityId);
return readerBehaviour;
})
.Step(world =>
{
world.Connection.RemoveComponent(EntityId, Position.ComponentId);
})
.Step(world =>
{
world.Connection.AddComponent(EntityId, Position.ComponentId, new Position.Update());
})
.Step((world, context) =>
{
var readerBehaviour = context;

Assert.IsNotNull(readerBehaviour.Reader);
Assert.IsTrue(readerBehaviour.Reader.IsValid);
});
}

[Test]
public void Reader_is_reenabled_if_component_regained_with_aggregate()
{
World
.Step(world =>
{
world.Connection.CreateEntity(EntityId, GetTemplate());
})
.Step(world =>
{
var (_, readerBehaviour) = world.CreateGameObject<MultipleComponentBehaviour>(EntityId);
return readerBehaviour;
})
.Step(world =>
{
world.Connection.RemoveComponent(EntityId, Position.ComponentId);
})
.Step(world =>
{
world.Connection.AddComponent(EntityId, Position.ComponentId, new Position.Update());
})
.Step((world, context) =>
{
var readerBehaviour = context;

Assert.IsNotNull(readerBehaviour.DependencyTestReader);
Assert.IsTrue(readerBehaviour.DependencyTestReader.IsValid);
});
}

[Test]
public void Writer_is_disabled_if_loses_auth()
{
Expand Down Expand Up @@ -148,6 +209,7 @@ private static EntityTemplate GetTemplate()
{
var template = new EntityTemplate();
template.AddComponent(new Position.Snapshot(), "worker");
template.AddComponent(new DependencyTest.Snapshot(), "worker");
template.AddComponent(new TestCommands.Snapshot(), "worker");
return template;
}
Expand Down Expand Up @@ -179,6 +241,12 @@ private class MultipleReaderBehaviour : MonoBehaviour
[Require] public PositionReader PositionReader;
[Require] public TestCommandsReader TestCommandsReader;
}

private class MultipleComponentBehaviour : MonoBehaviour
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
{
[Require] public PositionReader PositionReader;
[Require] public DependencyTestReader DependencyTestReader;
}

#pragma warning restore 649

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public void RemoveComponent(long entityId, uint componentId)
{
currentDiff.RemoveComponent(entityId, componentId);
}

public void AddComponent<T>(long entityId, uint componentId, T component)
where T : ISpatialComponentUpdate
{
currentDiff.AddComponent(component, entityId, componentId);
}

public void UpdateComponentAndAddEvents<TUpdate, TEvent>(long entityId, uint componentId, TUpdate update,
params TEvent[] events)
Expand Down