Skip to content

Commit 4838f97

Browse files
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.
1 parent 35053bd commit 4838f97

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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)