-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathTestCoordinatorTests.cs
77 lines (65 loc) · 2.54 KB
/
TestCoordinatorTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Unity.Netcode.MultiprocessRuntimeTests
{
[TestFixture(1)]
[TestFixture(2)]
public class TestCoordinatorTests : BaseMultiprocessTests
{
private int m_WorkerCount;
protected override int WorkerCount => m_WorkerCount;
protected override bool IsPerformanceTest => false;
public TestCoordinatorTests(int workerCount)
{
m_WorkerCount = workerCount;
}
private static float s_ValueToValidateAgainst;
private static void ValidateSimpleCoordinatorTestValue(float resultReceived)
{
Assert.AreEqual(s_ValueToValidateAgainst, resultReceived);
}
private static void ExecuteSimpleCoordinatorTest()
{
s_ValueToValidateAgainst = float.PositiveInfinity;
TestCoordinator.Instance.WriteTestResultsServerRpc(s_ValueToValidateAgainst);
}
private static void ExecuteWithArgs(byte[] args)
{
s_ValueToValidateAgainst = args[0];
TestCoordinator.Instance.WriteTestResultsServerRpc(s_ValueToValidateAgainst);
}
[UnityTest]
public IEnumerator CheckTestCoordinator()
{
// Sanity check for TestCoordinator
// Call the method
TestCoordinator.Instance.InvokeFromMethodActionRpc(ExecuteSimpleCoordinatorTest);
var nbResults = 0;
for (int i = 0; i < WorkerCount; i++) // wait and test for the two clients
{
yield return new WaitUntil(TestCoordinator.ResultIsSet());
var (clientId, result) = TestCoordinator.ConsumeCurrentResult().Take(1).Single();
Assert.Greater(result, 0f);
nbResults++;
}
Assert.That(nbResults, Is.EqualTo(WorkerCount));
}
[UnityTest]
public IEnumerator CheckTestCoordinatorWithArgs()
{
TestCoordinator.Instance.InvokeFromMethodActionRpc(ExecuteWithArgs, 99);
var nbResults = 0;
for (int i = 0; i < WorkerCount; i++) // wait and test for the two clients
{
yield return new WaitUntil(TestCoordinator.ResultIsSet());
var (clientId, result) = TestCoordinator.ConsumeCurrentResult().Take(1).Single();
Assert.That(result, Is.EqualTo(99));
nbResults++;
}
Assert.That(nbResults, Is.EqualTo(WorkerCount));
}
}
}