Skip to content

Commit a30d9be

Browse files
committed
Fix integration test helpers
1 parent d3cea31 commit a30d9be

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,37 +1669,21 @@ public bool WaitForConditionOrTimeOutWithTimeTravel(IConditionalPredicate condit
16691669
return success;
16701670
}
16711671

1672-
/// <summary>
1673-
/// Waits until the specified condition returns true or a timeout occurs, then asserts if the timeout was reached.
1674-
/// </summary>
1675-
/// <param name="checkForCondition">A delegate that returns true when the desired condition is met.</param>
1676-
/// <param name="timeoutErrorMessage">The error message to include in the assertion if the timeout is reached.</param>
1677-
/// <param name="timeOutHelper">An optional <see cref="TimeoutHelper"/> to control the timeout period. If null, the default timeout is used.</param>
1678-
/// <returns>An <see cref="IEnumerator"/> for use in Unity coroutines.</returns>
1679-
protected IEnumerator WaitForConditionOrAssert(Func<bool> checkForCondition, string timeoutErrorMessage, TimeoutHelper timeOutHelper = null)
1680-
{
1681-
yield return WaitForConditionOrTimeOut(checkForCondition, timeOutHelper);
1682-
AssertOnTimeout(timeoutErrorMessage, timeOutHelper);
1683-
}
1684-
16851672
/// <summary>
16861673
/// Waits until the specified condition returns true or a timeout occurs, then asserts if the timeout was reached.
16871674
/// This overload allows the condition to provide additional error details via a <see cref="StringBuilder"/>.
16881675
/// </summary>
16891676
/// <param name="checkForCondition">A delegate that takes a <see cref="StringBuilder"/> for error details and returns true when the desired condition is met.</param>
1690-
/// <param name="timeoutErrorMessage">The error message to include in the assertion if the timeout is reached. The information on the StringBuilder will be appended on a new line</param>
16911677
/// <param name="timeOutHelper">An optional <see cref="TimeoutHelper"/> to control the timeout period. If null, the default timeout is used.</param>
16921678
/// <returns>An <see cref="IEnumerator"/> for use in Unity coroutines.</returns>
1693-
protected IEnumerator WaitForConditionOrAssert(Func<StringBuilder, bool> checkForCondition, string timeoutErrorMessage, TimeoutHelper timeOutHelper = null)
1679+
protected IEnumerator WaitForConditionOrTimeOut(Func<StringBuilder, bool> checkForCondition, TimeoutHelper timeOutHelper = null)
16941680
{
1695-
var errorBuilder = new StringBuilder();
16961681
yield return WaitForConditionOrTimeOut(() =>
16971682
{
16981683
// Clear errorBuilder before each check to ensure the errorBuilder only contains information from the lastest run
1699-
errorBuilder.Clear();
1700-
return checkForCondition(errorBuilder);
1684+
m_InternalErrorLog.Clear();
1685+
return checkForCondition(m_InternalErrorLog);
17011686
}, timeOutHelper);
1702-
AssertOnTimeout($"{timeoutErrorMessage}\n{errorBuilder}", timeOutHelper);
17031687
}
17041688

17051689
/// <summary>
@@ -2057,7 +2041,14 @@ private void InitializeTestConfiguration(NetworkTopologyTypes networkTopologyTyp
20572041
protected void AssertOnTimeout(string timeOutErrorMessage, TimeoutHelper assignedTimeoutHelper = null)
20582042
{
20592043
var timeoutHelper = assignedTimeoutHelper ?? s_GlobalTimeoutHelper;
2060-
Assert.False(timeoutHelper.TimedOut, timeOutErrorMessage);
2044+
2045+
if (m_InternalErrorLog.Length > 0)
2046+
{
2047+
Assert.False(timeoutHelper.TimedOut, $"{timeOutErrorMessage}\n{m_InternalErrorLog}");
2048+
m_InternalErrorLog.Clear();
2049+
}
2050+
2051+
Assert.False(timeoutHelper.TimedOut, $"{timeOutErrorMessage}");
20612052
}
20622053

20632054

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ private IEnumerator RunSceneEventCallbackTest(ClientType clientType, Action acti
106106
// Load the scene initially
107107
authority.SceneManager.LoadScene(k_SceneToLoad, LoadSceneMode.Additive);
108108

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

111112
// Wait for any pending messages to be processed
112113
yield return null;
@@ -179,14 +180,16 @@ private IEnumerator RunSceneEventCallbackTest(ClientType clientType, Action acti
179180
{
180181
Assert.That(authority.SceneManager.LoadScene(loadCall, LoadSceneMode.Additive) == SceneEventProgressStatus.Started);
181182

182-
yield return WaitForConditionOrAssert(ValidateSceneIsLoaded, $"[Test] Timed out waiting for client to load the scene {k_SceneToLoad}!");
183+
yield return WaitForConditionOrTimeOut(ValidateSceneIsLoaded);
184+
AssertOnTimeout($"[Test] Timed out waiting for client to load the scene {k_SceneToLoad}!");
183185
}
184186
else
185187
{
186188
Assert.That(loadedScene.name, Is.EqualTo(k_SceneToLoad), "scene was not loaded!");
187189
Assert.That(authority.SceneManager.UnloadScene(loadedScene) == SceneEventProgressStatus.Started);
188190

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

192195
// Wait for all messages to process
@@ -219,7 +222,7 @@ private bool ValidateSceneIsLoaded(StringBuilder errorBuilder)
219222
}
220223
}
221224

222-
return true;
225+
return false;
223226
}
224227

225228
private bool ValidateSceneIsUnloaded()

0 commit comments

Comments
 (0)