Skip to content

Commit c7996c6

Browse files
fix: [BACKPORT] android time test failures due to edge case float precision errors (Unity-Technologies#3352)
This PR is a backport of Unity-Technologies#3351 Some changes were not included because those were already present on develop branch. All Android tests passed before merging Co-authored-by: Noel Stephens <[email protected]>
1 parent f6d498d commit c7996c6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/Timing/TimeInitializationTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ public IEnumerator TestClientTimeInitializationOnConnect([Values(0, 1f)] float s
4343
yield return new WaitUntil(() => server.NetworkTickSystem.ServerTime.Tick > 2);
4444

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

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

5152
yield return new WaitForSeconds(clientStartDelay);
5253

0 commit comments

Comments
 (0)