Skip to content

Commit 730e160

Browse files
committed
Get more information on test failures
1 parent 30d7fb3 commit 730e160

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,12 +1635,6 @@ public static IEnumerator WaitForConditionOrTimeOut(IConditionalPredicate condit
16351635
throw new ArgumentNullException($"checkForCondition cannot be null!");
16361636
}
16371637

1638-
// If none is provided we use the default global time out helper
1639-
if (timeOutHelper == null)
1640-
{
1641-
timeOutHelper = s_GlobalTimeoutHelper;
1642-
}
1643-
16441638
conditionalPredicate.Started();
16451639
yield return WaitForConditionOrTimeOut(conditionalPredicate.HasConditionBeenReached, timeOutHelper);
16461640
conditionalPredicate.Finished(timeOutHelper.TimedOut);
@@ -1669,6 +1663,19 @@ public bool WaitForConditionOrTimeOutWithTimeTravel(IConditionalPredicate condit
16691663
return success;
16701664
}
16711665

1666+
public IEnumerator WaitForConditionOrAssert(Func<bool> checkForCondition, string timeoutErrorMessage, TimeoutHelper timeOutHelper = null)
1667+
{
1668+
yield return WaitForConditionOrTimeOut(checkForCondition, timeOutHelper);
1669+
AssertOnTimeout(timeoutErrorMessage, timeOutHelper);
1670+
}
1671+
1672+
public IEnumerator WaitForConditionOrAssert(Func<StringBuilder, bool> checkForCondition, string timeoutErrorMessage, TimeoutHelper timeOutHelper = null)
1673+
{
1674+
var errorBuilder = new StringBuilder();
1675+
yield return WaitForConditionOrTimeOut(() => checkForCondition(errorBuilder), timeOutHelper);
1676+
AssertOnTimeout($"{timeoutErrorMessage}\n{errorBuilder.ToString()}", timeOutHelper);
1677+
}
1678+
16721679
/// <summary>
16731680
/// Validates that all remote clients (i.e. non-server) detect they are connected
16741681
/// to the server and that the server reflects the appropriate number of clients

testproject/Assets/Tests/Runtime/NetworkSceneManager/OnSceneEventCallbackTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Text;
45
using NUnit.Framework;
56
using Unity.Netcode;
67
using Unity.Netcode.TestHelpers.Runtime;
@@ -105,8 +106,7 @@ private IEnumerator RunSceneEventCallbackTest(ClientType clientType, Action acti
105106
// Load the scene initially
106107
authority.SceneManager.LoadScene(k_SceneToLoad, LoadSceneMode.Additive);
107108

108-
yield return WaitForConditionOrTimeOut(ValidateSceneIsLoaded);
109-
AssertOnTimeout($"Timed out waiting for client to load the scene {k_SceneToLoad}!");
109+
yield return WaitForConditionOrAssert(ValidateSceneIsLoaded, $"[Setup] Timed out waiting for client to load the scene {k_SceneToLoad}!");
110110

111111
// Wait for any pending messages to be processed
112112
yield return null;
@@ -179,16 +179,14 @@ private IEnumerator RunSceneEventCallbackTest(ClientType clientType, Action acti
179179
{
180180
Assert.That(authority.SceneManager.LoadScene(loadCall, LoadSceneMode.Additive) == SceneEventProgressStatus.Started);
181181

182-
yield return WaitForConditionOrTimeOut(ValidateSceneIsLoaded);
183-
AssertOnTimeout($"Timed out waiting for client to load the scene {k_SceneToLoad}!");
182+
yield return WaitForConditionOrAssert(ValidateSceneIsLoaded, $"[Test] Timed out waiting for client to load the scene {k_SceneToLoad}!");
184183
}
185184
else
186185
{
187186
Assert.That(loadedScene.name, Is.EqualTo(k_SceneToLoad), "scene was not loaded!");
188187
Assert.That(authority.SceneManager.UnloadScene(loadedScene) == SceneEventProgressStatus.Started);
189188

190-
yield return WaitForConditionOrTimeOut(ValidateSceneIsUnloaded);
191-
AssertOnTimeout($"Timed out waiting for client to unload the scene {k_SceneToLoad}!");
189+
yield return WaitForConditionOrAssert(ValidateSceneIsUnloaded, $"[Test] Timed out waiting for client to unload the scene {k_SceneToLoad}!");
192190
}
193191

194192
// Wait for all messages to process
@@ -202,19 +200,21 @@ private IEnumerator RunSceneEventCallbackTest(ClientType clientType, Action acti
202200
managerToTest.SceneManager.OnSceneEvent -= OnSceneEvent;
203201
}
204202

205-
private bool ValidateSceneIsLoaded()
203+
private bool ValidateSceneIsLoaded(StringBuilder errorBuilder)
206204
{
207205
foreach (var manager in m_NetworkManagers)
208206
{
209207
// default will have isLoaded as false so we can get the scene or default and test on isLoaded
210208
var loadedScene = manager.SceneManager.ScenesLoaded.Values.FirstOrDefault(scene => scene.name == k_SceneToLoad);
211209
if (!loadedScene.isLoaded)
212210
{
211+
errorBuilder.AppendLine($"[ValidateIsLoaded] Scene {loadedScene.name} exists but is not loaded!");
213212
return false;
214213
}
215214

216215
if (manager.SceneManager.SceneEventProgressTracking.Count > 0)
217216
{
217+
errorBuilder.AppendLine($"[ValidateIsLoaded] NetworkManager {manager.name} still has progress tracking events.");
218218
return false;
219219
}
220220
}

0 commit comments

Comments
 (0)