Skip to content

Commit c71edf9

Browse files
authored
test: NetworkTickSystem test (#630)
* test: NetworkTickSystem test * test: NetworkTickSystem test, removed unneeded code
1 parent 8ea85ea commit c71edf9

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections;
3+
using UnityEngine;
4+
using UnityEngine.TestTools;
5+
using NUnit.Framework;
6+
7+
namespace MLAPI.RuntimeTests
8+
{
9+
public class TickSystemTests: IDisposable
10+
{
11+
private NetworkTickSystem m_TickSystem = null;
12+
private float m_TestDuration = 5.0f;
13+
private float m_SleepInterval = 0.001f;
14+
private float m_TickInterval = 0.010f;
15+
16+
public void Dispose()
17+
{
18+
m_TickSystem.Dispose();
19+
m_TickSystem = null;
20+
NetworkUpdateLoop.UnregisterLoopSystems();
21+
}
22+
23+
[UnityTest]
24+
public IEnumerator VerifyTickSystem()
25+
{
26+
m_TickSystem = new NetworkTickSystem(m_TickInterval);
27+
28+
ushort tick0 = m_TickSystem.GetTick();
29+
ushort lastTick = tick0;
30+
float t0 = Time.unscaledTime;
31+
float t1;
32+
33+
do
34+
{
35+
t1 = Time.unscaledTime;
36+
ushort tick = m_TickSystem.GetTick();
37+
38+
Assert.IsTrue(tick >= lastTick); // check monotonicity of ticks
39+
40+
lastTick = tick;
41+
yield return new WaitForSeconds(m_SleepInterval);
42+
} while (t1 - t0 <= m_TestDuration);
43+
44+
int ticks = lastTick - tick0;
45+
int expectedTicks = (int)(m_TestDuration / m_TickInterval);
46+
47+
// check overall number of ticks is within one tick of the expected value
48+
Assert.IsTrue(Math.Abs(expectedTicks - ticks) < 2);
49+
}
50+
}
51+
}

com.unity.multiplayer.mlapi/Tests/Runtime/TickSystemTests.cs.meta

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

0 commit comments

Comments
 (0)