-
Notifications
You must be signed in to change notification settings - Fork 461
test: NetworkTickSystem test #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using System; | ||
| using System.Collections; | ||
| using UnityEngine; | ||
| using UnityEngine.TestTools; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace MLAPI.RuntimeTests | ||
| { | ||
| public class TickSystemTests: IDisposable | ||
| { | ||
| private NetworkTickSystem m_TickSystem = null; | ||
| private float m_TestDuration = 5.0f; | ||
| private float m_SleepInterval = 0.001f; | ||
| private float m_TickInterval = 0.010f; | ||
|
|
||
| public void Dispose() | ||
| { | ||
| m_TickSystem.Dispose(); | ||
| m_TickSystem = null; | ||
| NetworkUpdateLoop.UnregisterLoopSystems(); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| public IEnumerator VerifyTickSystem() | ||
| { | ||
| m_TickSystem = new NetworkTickSystem(m_TickInterval); | ||
|
|
||
| ushort tick0 = m_TickSystem.GetTick(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Standards Suggestion ( minor nit-pick related ) There are several places this could be applied within VerifyTickSystem |
||
| ushort lastTick = tick0; | ||
| float t0 = Time.unscaledTime; | ||
| float t1; | ||
|
|
||
| do | ||
| { | ||
| t1 = Time.unscaledTime; | ||
| ushort tick = m_TickSystem.GetTick(); | ||
|
|
||
| Assert.IsTrue(tick >= lastTick); // check monotonicity of ticks | ||
|
|
||
| lastTick = tick; | ||
| yield return new WaitForSeconds(m_SleepInterval); | ||
| } while (t1 - t0 <= m_TestDuration); | ||
|
|
||
| int ticks = lastTick - tick0; | ||
| int expectedTicks = (int)(m_TestDuration / m_TickInterval); | ||
|
|
||
| // check overall number of ticks is within one tick of the expected value | ||
| Assert.IsTrue(Math.Abs(expectedTicks - ticks) < 2); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: you might want to consider using
[TearDown] void Teardown() { ... }instead ofDispose()but both would work fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.nunit.org/articles/nunit/technical-notes/usage/SetUp-and-TearDown.html