Skip to content

Commit d762083

Browse files
authored
feat: NetcodeIntegrationTestHelpers.WaitForTicks(netMgr, count) (#1766)
1 parent d260894 commit d762083

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ public static void MarkAsSceneObjectRoot(GameObject networkObjectRoot, NetworkMa
467467
}
468468
}
469469

470+
/// <summary>
471+
/// Waits (yields) until specified amount of network ticks has been passed.
472+
/// </summary>
473+
public static IEnumerator WaitForTicks(NetworkManager networkManager, int count)
474+
{
475+
var targetTick = networkManager.NetworkTickSystem.LocalTime.Tick + count;
476+
yield return new WaitUntil(() => networkManager.NetworkTickSystem.LocalTime.Tick >= targetTick);
477+
}
478+
470479
/// <summary>
471480
/// Waits on the client side to be connected.
472481
/// </summary>

com.unity.netcode.gameobjects/Tests/Runtime/Physics/NetworkRigidbody2DTest.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
5252
Assert.IsNotNull(serverPlayer);
5353
Assert.IsNotNull(clientPlayer);
5454

55-
yield return WaitForTicks(m_ServerNetworkManager, 5);
55+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 5);
5656

5757
// server rigidbody has authority and should have a kinematic mode of false
5858
Assert.True(serverPlayer.GetComponent<Rigidbody2D>().isKinematic == Kinematic);
@@ -65,20 +65,14 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
6565
// despawn the server player, (but keep it around on the server)
6666
serverPlayer.GetComponent<NetworkObject>().Despawn(false);
6767

68-
yield return WaitForTicks(m_ServerNetworkManager, 5);
68+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 5);
6969

7070
// This should equal Kinematic
7171
Assert.IsTrue(serverPlayer.GetComponent<Rigidbody2D>().isKinematic == Kinematic);
7272

73-
yield return WaitForTicks(m_ServerNetworkManager, 5);
73+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 5);
7474

7575
Assert.IsTrue(clientPlayer == null); // safety check that object is actually despawned.
7676
}
77-
78-
public IEnumerator WaitForTicks(NetworkManager networkManager, int count)
79-
{
80-
int nextTick = networkManager.NetworkTickSystem.LocalTime.Tick + count;
81-
yield return new WaitUntil(() => networkManager.NetworkTickSystem.LocalTime.Tick >= nextTick);
82-
}
8377
}
8478
}

com.unity.netcode.gameobjects/Tests/Runtime/Physics/NetworkRigidbodyTest.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
5252
Assert.IsNotNull(serverPlayer, "serverPlayer is not null");
5353
Assert.IsNotNull(clientPlayer, "clientPlayer is not null");
5454

55-
yield return WaitForTicks(m_ServerNetworkManager, 3);
55+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 3);
5656

5757
// server rigidbody has authority and should have a kinematic mode of false
5858
Assert.True(serverPlayer.GetComponent<Rigidbody>().isKinematic == Kinematic, "serverPlayer kinematic");
@@ -65,19 +65,13 @@ public IEnumerator TestRigidbodyKinematicEnableDisable()
6565
// despawn the server player (but keep it around on the server)
6666
serverPlayer.GetComponent<NetworkObject>().Despawn(false);
6767

68-
yield return WaitForTicks(m_ServerNetworkManager, 3);
68+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 3);
6969

7070
Assert.IsTrue(serverPlayer.GetComponent<Rigidbody>().isKinematic == Kinematic, "serverPlayer second kinematic");
7171

72-
yield return WaitForTicks(m_ServerNetworkManager, 3);
72+
yield return NetcodeIntegrationTestHelpers.WaitForTicks(m_ServerNetworkManager, 3);
7373

7474
Assert.IsTrue(clientPlayer == null, "clientPlayer being null"); // safety check that object is actually despawned.
7575
}
76-
77-
public IEnumerator WaitForTicks(NetworkManager networkManager, int count)
78-
{
79-
int nextTick = networkManager.NetworkTickSystem.LocalTime.Tick + count;
80-
yield return new WaitUntil(() => networkManager.NetworkTickSystem.LocalTime.Tick >= nextTick);
81-
}
8276
}
8377
}

0 commit comments

Comments
 (0)