Skip to content

test: implement extra features on top of existing NetworkUpdateLoopTests to cover other test cases #559

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 2 commits into from
Mar 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ private void Awake()
this.RegisterNetworkUpdate(NetworkUpdateStage.FixedUpdate);
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate);
this.RegisterNetworkUpdate(NetworkUpdateStage.PreLateUpdate);
this.RegisterNetworkUpdate(NetworkUpdateStage.PostLateUpdate);

// intentionally try to register for 'PreUpdate' stage twice
// it should be ignored and the instance should not be registered twice
// otherwise test would fail because it would call 'OnPreUpdate()' twice
// which would ultimately increment 'netUpdates[idx]' integer twice
// and cause 'Assert.AreEqual()' to fail the test
this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate);
}

public void NetworkUpdate(NetworkUpdateStage updateStage)
Expand All @@ -239,6 +247,9 @@ public void NetworkUpdate(NetworkUpdateStage updateStage)
case NetworkUpdateStage.PreLateUpdate:
UpdateCallbacks.OnPreLateUpdate();
break;
case NetworkUpdateStage.PostLateUpdate:
UpdateCallbacks.OnPostLateUpdate();
break;
}
}

Expand Down Expand Up @@ -269,7 +280,8 @@ public IEnumerator UpdateStagesMixed()
const int kNetFixedUpdateIndex = 0;
const int kNetPreUpdateIndex = 1;
const int kNetPreLateUpdateIndex = 2;
int[] netUpdates = new int[3];
const int kNetPostLateUpdateIndex = 3;
int[] netUpdates = new int[4];
const int kMonoFixedUpdateIndex = 0;
const int kMonoUpdateIndex = 1;
const int kMonoLateUpdateIndex = 2;
Expand Down Expand Up @@ -304,6 +316,14 @@ public IEnumerator UpdateStagesMixed()
netUpdates[kNetPreLateUpdateIndex]++;
Assert.AreEqual(monoUpdates[kMonoLateUpdateIndex] + 1, netUpdates[kNetPreLateUpdateIndex]);
}
},
OnPostLateUpdate = () =>
{
if (isTesting)
{
netUpdates[kNetPostLateUpdateIndex]++;
Assert.AreEqual(netUpdates[kNetPostLateUpdateIndex], netUpdates[kNetPreLateUpdateIndex]);
}
}
};
gameScript.BehaviourCallbacks = new MonoBehaviourCallbacks
Expand Down