Skip to content

test[NetworkVariable]: adjusting netvars manual tests #583

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

Merged
merged 1 commit into from
Mar 10, 2021
Merged
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
53 changes: 26 additions & 27 deletions testproject/Assets/Scripts/Testing/ManualNetworkVariableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ public class ManualNetworkVariableTest : NetworkBehaviour
private string m_Problems = string.Empty;
private int m_Count = 0;

// todo: address issue with initial values
private const int k_WaitIterations = 5;
private const int k_EndIterations = 1000;

void Start()
{
Debug.Log("Start");
m_TestVar.Value = 0;
m_TestVar.OnValueChanged = ValueChanged;
m_TestVar.Settings.WritePermission = NetworkVariablePermission.Everyone;

if (IsOwner)
{
m_TestVar.Value = 0;
}
}

void Awake()
Expand All @@ -45,7 +46,7 @@ private void FixedUpdate()

private void ValueChanged(int before, int after)
{
if (!IsLocalPlayer && !IsServer)
if (!IsOwner && !IsServer)
{
// compute the delta in tick between client and server,
// as seen from the client, when it receives a value not from itself
Expand All @@ -54,37 +55,36 @@ private void ValueChanged(int before, int after)
int delta = m_TestVar.LocalTick - m_TestVar.RemoteTick;
m_Count++;

if (m_Count > k_WaitIterations)
if (!m_Valid)
{
if (!m_Valid)
m_Valid = true;
m_MinDelta = delta;
m_MaxDelta = delta;
m_LastRemoteTick = m_TestVar.RemoteTick;
}
else
{
m_MinDelta = Math.Min(delta, m_MinDelta);
m_MaxDelta = Math.Max(delta, m_MaxDelta);

// tick should not go backward until wrap around (which should be a long time)
if (m_TestVar.RemoteTick == m_LastRemoteTick)
{
m_Valid = true;
m_MinDelta = delta;
m_MaxDelta = delta;
m_LastRemoteTick = m_TestVar.RemoteTick;
m_Problems += "Same remote tick receive twice\n";
}
else
else if (m_TestVar.RemoteTick < m_LastRemoteTick)
{
m_MinDelta = Math.Min(delta, m_MinDelta);
m_MaxDelta = Math.Max(delta, m_MaxDelta);

// tick should not go backward until wrap around (which should be a long time)
if (m_TestVar.RemoteTick == m_LastRemoteTick)
{
m_Problems += "Same remote tick receive twice\n";
}
else if (m_TestVar.RemoteTick < m_LastRemoteTick)
{
m_Problems += "Ticks went backward\n";
}
m_Problems += "Ticks went backward\n";
}
}
}
}

if (m_Count == k_EndIterations)
{
if (m_Problems == "" && Math.Abs(m_MaxDelta - m_MinDelta) < 3)
// Let's be reasonable and allow a 5 tick difference
// that could be due to timing difference, lag, queueing
if (m_Problems == "" && Math.Abs(m_MaxDelta - m_MinDelta) < 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would tend to replace the '5' as a constant to show meaning, like k_MaxAllowedTickDifference, and then say why '5', but I'm glad to have this comment for now

{
Debug.Log("**** TEST PASSED ****");
}
Expand All @@ -98,9 +98,8 @@ private void ValueChanged(int before, int after)
Debug.Log(m_Problems);
}
}

enabled = false;
}
}
}
}
}