Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions com.unity.multiplayer.mlapi/Tests/Runtime/TickSystemTests.cs
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()
Copy link
Copy Markdown
Contributor

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 of Dispose() but both would work fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
m_TickSystem.Dispose();
m_TickSystem = null;
NetworkUpdateLoop.UnregisterLoopSystems();
}

[UnityTest]
public IEnumerator VerifyTickSystem()
{
m_TickSystem = new NetworkTickSystem(m_TickInterval);

ushort tick0 = m_TickSystem.GetTick();
Copy link
Copy Markdown
Member

@NoelStephensUnity NoelStephensUnity Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standards Suggestion ( minor nit-pick related )
When you have the time, it would be more standards compliant to replace all of the locally scoped variable declarations as "var" and not the actual type.
Example:
From this: ushort tick0 = m_TickSystem.GetTick();
To this: var tick0 = m_TickSystem.GetTick();

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);
}
}
}
11 changes: 11 additions & 0 deletions com.unity.multiplayer.mlapi/Tests/Runtime/TickSystemTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.