Skip to content

fix: android time test failures due to edge case float precision errors #3351

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 5 commits into from
Mar 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public IEnumerator PlayerLoopTimeTest_WithDifferentTimeScale([Values(0.0f, 0.1f,
public IEnumerator CorrectAmountTicksTest()
{
NetworkTickSystem tickSystem = NetworkManager.Singleton.NetworkTickSystem;
float delta = tickSystem.LocalTime.FixedDeltaTime;
double delta = tickSystem.LocalTime.FixedDeltaTimeAsDouble;
int previous_localTickCalculated = 0;
int previous_serverTickCalculated = 0;

Expand All @@ -79,7 +79,6 @@ public IEnumerator CorrectAmountTicksTest()
previous_localTickCalculated++;
}


tickCalculated = NetworkManager.Singleton.ServerTime.Time / delta;
previous_serverTickCalculated = (int)tickCalculated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public IEnumerator TestClientTimeInitializationOnConnect([Values(0, 1f)] float s
yield return new WaitUntil(() => server.NetworkTickSystem.ServerTime.Tick > 2);

var serverTimePassed = server.NetworkTickSystem.ServerTime.Time;
var expectedServerTickCount = Mathf.FloorToInt((float)(serverTimePassed * 30));

// Use FixedDeltaTimeAsDouble and divide the tick frequency into the time passed to get the accurate tick count
var expectedServerTickCount = (int)System.Math.Floor(serverTimePassed / server.ServerTime.FixedDeltaTimeAsDouble);
var ticksPassed = server.NetworkTickSystem.ServerTime.Tick - serverTick;
Assert.AreEqual(expectedServerTickCount, ticksPassed);
Assert.AreEqual(expectedServerTickCount, ticksPassed, $"Calculated tick failed: Tick ({expectedServerTickCount}) TicksPassed ({ticksPassed}) Server Tick ({server.NetworkTickSystem.ServerTime.Tick}) Prev-Server Tick ({serverTick})");

yield return new WaitForSeconds(clientStartDelay);

Expand Down