Skip to content

Commit 0868ea3

Browse files
fix(util): add timeouts to WaitUntil calls in tests
Add 5-second timeouts to UniTask.WaitUntil calls to prevent tests from hanging indefinitely if there's a regression. Uses CancellationTokenSource with timeout for deterministic failure behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net>
1 parent cdddf14 commit 0868ea3

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

UnityProject/Packages/com.jasonxudeveloper.jengine.util/Tests/Editor/JActionAwaiterTests.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ public IEnumerator OnCompleted_DuringExecution_RegistersCallback() => UniTask.To
218218
Assert.IsFalse(invoked);
219219

220220
// Wait for completion by polling (don't use await handle - it overwrites OnCompleted callback)
221-
await UniTask.WaitUntil(() => invoked || !handle.Executing);
221+
// Use timeout to avoid hanging indefinitely if there's a regression
222+
using var cts = new System.Threading.CancellationTokenSource(System.TimeSpan.FromSeconds(5));
223+
await UniTask.WaitUntil(() => invoked || !handle.Executing, cancellationToken: cts.Token);
222224

223225
// Callback should have been invoked
224226
Assert.IsTrue(invoked);
@@ -284,8 +286,9 @@ public IEnumerator UnsafeOnCompleted_DuringExecution_RegistersCallback() => UniT
284286
// Not invoked immediately (still executing)
285287
Assert.IsFalse(invoked);
286288

287-
// Wait for completion by polling
288-
await UniTask.WaitUntil(() => invoked || !handle.Executing);
289+
// Wait for completion by polling with timeout to avoid hanging indefinitely
290+
using var cts = new System.Threading.CancellationTokenSource(System.TimeSpan.FromSeconds(5));
291+
await UniTask.WaitUntil(() => invoked || !handle.Executing, cancellationToken: cts.Token);
289292

290293
// Callback should have been invoked
291294
Assert.IsTrue(invoked);
@@ -391,8 +394,9 @@ public IEnumerator Cancel_DuringNestedExecution_StopsExecution() => UniTask.ToCo
391394

392395
var handle = action.ExecuteAsync();
393396

394-
// Wait for first step
395-
await UniTask.WaitUntil(() => step1);
397+
// Wait for first step with timeout to avoid hanging indefinitely
398+
using var cts = new System.Threading.CancellationTokenSource(System.TimeSpan.FromSeconds(5));
399+
await UniTask.WaitUntil(() => step1, cancellationToken: cts.Token);
396400

397401
handle.Cancel();
398402
await handle;

0 commit comments

Comments
 (0)