File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
com.unity.multiplayer.mlapi/Tests/Runtime Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments