Skip to content

Commit 8376844

Browse files
fix: 2.7.0 test instabilities (#3768)
* test - fix Resolving the PeerDisconnectCallbackTests instability where sometimes the disconnect notification is processed prior to the targeted client's NetworkManager having completely disconnected and shutdown (this would only have a chance of happening if server disconnects the client). Hoping to resolve the instability with the ParentingInSceneObjectsTests resulting in a false failure. * test fix Fixing potential cause for instabilities on this set of tests due to the initial network prefab transform settings not being applied to the prefab but applied to the spawned instances which could be causing issues since they were being applied to the non-authority instances. This fix moves the applied test NetworkTrransform settings to the player prefab prior to spawning any instances.
1 parent 35053bd commit 8376844

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

com.unity.netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformBase.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ protected override void OnCreatePlayerPrefab()
230230
{
231231
var networkTransformTestComponent = m_PlayerPrefab.AddComponent<NetworkTransformTestComponent>();
232232
networkTransformTestComponent.ServerAuthority = m_Authority == Authority.ServerAuthority;
233+
// Handle setting up additional transform settings for the current test here.
234+
networkTransformTestComponent.UseUnreliableDeltas = UseUnreliableDeltas();
235+
networkTransformTestComponent.UseHalfFloatPrecision = m_Precision == Precision.Half;
236+
networkTransformTestComponent.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
237+
networkTransformTestComponent.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
233238
}
234239

235240
protected override void OnServerAndClientsCreated()
@@ -291,19 +296,6 @@ protected virtual void OnClientsAndServerConnectedSetup()
291296
// Get the NetworkTransformTestComponent to make sure the client side is ready before starting test
292297
m_AuthoritativeTransform = m_AuthoritativePlayer.GetComponent<NetworkTransformTestComponent>();
293298
m_NonAuthoritativeTransform = m_NonAuthoritativePlayer.GetComponent<NetworkTransformTestComponent>();
294-
295-
// Setup whether we are or are not using unreliable deltas
296-
m_AuthoritativeTransform.UseUnreliableDeltas = UseUnreliableDeltas();
297-
m_NonAuthoritativeTransform.UseUnreliableDeltas = UseUnreliableDeltas();
298-
299-
m_AuthoritativeTransform.UseHalfFloatPrecision = m_Precision == Precision.Half;
300-
m_AuthoritativeTransform.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
301-
m_AuthoritativeTransform.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
302-
m_NonAuthoritativeTransform.UseHalfFloatPrecision = m_Precision == Precision.Half;
303-
m_NonAuthoritativeTransform.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
304-
m_NonAuthoritativeTransform.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
305-
306-
307299
m_OwnerTransform = m_AuthoritativeTransform.IsOwner ? m_AuthoritativeTransform : m_NonAuthoritativeTransform;
308300
}
309301

com.unity.netcode.gameobjects/Tests/Runtime/PeerDisconnectCallbackTests.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,21 @@ private void OnConnectionEventCallback(NetworkManager networkManager, Connection
8383
}
8484
}
8585

86+
private bool m_TargetClientShutdown;
87+
private NetworkManager m_TargetClient;
88+
89+
private void ClientToDisconnect_OnClientStopped(bool wasHost)
90+
{
91+
m_TargetClient.OnClientStopped -= ClientToDisconnect_OnClientStopped;
92+
m_TargetClientShutdown = true;
93+
}
94+
8695
[UnityTest]
8796
public IEnumerator TestPeerDisconnectCallback([Values] ClientDisconnectType clientDisconnectType, [Values(1ul, 2ul, 3ul)] ulong disconnectedClient)
8897
{
98+
m_TargetClientShutdown = false;
99+
m_TargetClient = m_ClientNetworkManagers[disconnectedClient - 1];
100+
m_TargetClient.OnClientStopped += ClientToDisconnect_OnClientStopped;
89101
foreach (var client in m_ClientNetworkManagers)
90102
{
91103
client.OnConnectionEvent += OnConnectionEventCallback;
@@ -129,12 +141,15 @@ public IEnumerator TestPeerDisconnectCallback([Values] ClientDisconnectType clie
129141
}
130142
else
131143
{
132-
yield return StopOneClient(m_ClientNetworkManagers[disconnectedClient - 1]);
144+
yield return StopOneClient(m_TargetClient);
133145
}
134146

135147
yield return WaitForConditionOrTimeOut(hooks);
148+
AssertOnTimeout($"Timed out waiting for all clients to receive the {nameof(ClientDisconnectedMessage)}!");
136149

137-
Assert.False(s_GlobalTimeoutHelper.TimedOut);
150+
// Make sure the target client is shutdown before performing validation
151+
yield return WaitForConditionOrTimeOut(() => m_TargetClientShutdown);
152+
AssertOnTimeout($"Timed out waiting for {m_TargetClient.name} to shutdown!");
138153

139154
foreach (var client in m_ClientNetworkManagers)
140155
{
@@ -182,5 +197,6 @@ public IEnumerator TestPeerDisconnectCallback([Values] ClientDisconnectType clie
182197
// Host receives peer disconnect, dedicated server does not
183198
Assert.AreEqual(m_UseHost ? 3 : 2, m_PeerDisconnectCount);
184199
}
200+
185201
}
186202
}

testproject/Assets/Tests/Runtime/ObjectParenting/ParentingInSceneObjectsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,21 @@ public IEnumerator InSceneParentingTest([Values] ParentingSpace parentingSpace)
332332
{
333333
InSceneParentChildHandler.AuthorityRootParent.DeparentSetValuesAndReparent();
334334

335-
yield return WaitForConditionOrTimeOut(ValidateClientsAgainstAuthorityTransformValues);
335+
yield return WaitForConditionOrTimeOut(() => ValidateAllChildrenParentingStatus(true));
336336
if (s_GlobalTimeoutHelper.TimedOut)
337337
{
338338
InSceneParentChildHandler.AuthorityRootParent.CheckChildren();
339339
yield return debugWait;
340340
}
341-
AssertOnTimeout($"[Final Pass][Deparent-Reparent-{i}] Timed out waiting for all clients transform values to match the server transform values!\n {m_ErrorValidationLog}");
341+
AssertOnTimeout($"[Final Pass][Deparent-Reparent-{i}] Timed out waiting for all children to be removed from their parent!\n {m_ErrorValidationLog}");
342342

343-
yield return WaitForConditionOrTimeOut(() => ValidateAllChildrenParentingStatus(true));
343+
yield return WaitForConditionOrTimeOut(ValidateClientsAgainstAuthorityTransformValues);
344344
if (s_GlobalTimeoutHelper.TimedOut)
345345
{
346346
InSceneParentChildHandler.AuthorityRootParent.CheckChildren();
347347
yield return debugWait;
348348
}
349-
AssertOnTimeout($"[Final Pass][Deparent-Reparent-{i}] Timed out waiting for all children to be removed from their parent!\n {m_ErrorValidationLog}");
349+
AssertOnTimeout($"[Final Pass][Deparent-Reparent-{i}] Timed out waiting for all clients transform values to match the server transform values!\n {m_ErrorValidationLog}");
350350
}
351351

352352
// In the final pass, we remove the second generation nested child

0 commit comments

Comments
 (0)