Skip to content

Commit

Permalink
Add test to verify task pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
BastianBlokland committed Jul 23, 2019
1 parent 31b0797 commit bd83ba0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/playmode/ComponentExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,50 @@ async Task IncrementCountAsync()
}
}

[UnityTest]
public IEnumerator TaskPausesWhenComponentIsDisabled()
{
var count = 0;
var go = new GameObject("TestGameObject");
var comp = go.AddComponent<MockComponent>();
comp.StartTask(IncrementCountAsync);

// Assert task is running.
yield return null;
Assert.AreEqual(1, count);

// Disable component.
comp.enabled = false;

// Assert task is paused.
yield return null;
Assert.AreEqual(1, count);
yield return null;
Assert.AreEqual(1, count);

// Enable component.
comp.enabled = true;

// Assert task is running.
yield return null;
Assert.AreEqual(2, count);
yield return null;
Assert.AreEqual(3, count);

// Cleanup.
Object.Destroy(go);

async Task IncrementCountAsync()
{
await Task.Yield();
count++;
await Task.Yield();
count++;
await Task.Yield();
count++;
}
}

[UnityTest]
public IEnumerator SameRunnerIsReusedForTheSameComponent()
{
Expand Down

0 comments on commit bd83ba0

Please sign in to comment.