Skip to content

Commit 3702281

Browse files
committed
Even more deterministic.
1 parent 2ebe7c8 commit 3702281

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/Components/Components/test/NavigationManagerTest.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,10 @@ public async Task OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
896896
var uri = "scheme://host/test";
897897
var testNavManager = new TestNavigationManagerWithExceptionHandling(baseUri);
898898
var expectedException = new InvalidOperationException("Test exception from OnNavigateTo");
899-
var tcs = new TaskCompletionSource();
899+
var exceptionHandledTcs = new TaskCompletionSource();
900900

901901
// First test: Initialize with a callback that throws exceptions
902-
testNavManager.Initialize(baseUri, uri, uri => testNavManager.GetErrorHandledTask(ThrowingMethod(uri)));
902+
testNavManager.Initialize(baseUri, uri, uri => testNavManager.GetErrorHandledTask(ThrowingMethod(uri), exceptionHandledTcs));
903903

904904
// Act & Assert
905905
// Verify that the wrapped callback handles the exception gracefully
@@ -908,23 +908,16 @@ public async Task OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
908908
// Should be null because the exception was handled gracefully
909909
Assert.Null(wrappedException);
910910

911-
await tcs.Task.WaitAsync(Timeout);
911+
await exceptionHandledTcs.Task;
912912

913913
// Verify that the exception was logged
914914
Assert.Single(testNavManager.HandledExceptions);
915915
Assert.Same(expectedException, testNavManager.HandledExceptions[0]);
916916

917917
async Task ThrowingMethod(string param)
918918
{
919-
try
920-
{
921-
await Task.Yield();
922-
throw expectedException;
923-
}
924-
finally
925-
{
926-
tcs.SetResult();
927-
}
919+
await Task.Yield();
920+
throw expectedException;
928921
}
929922
#nullable restore
930923
}
@@ -1017,7 +1010,7 @@ protected override void NavigateToCore(string uri, bool forceLoad)
10171010
}
10181011
}
10191012

1020-
public async Task GetErrorHandledTask(Task taskToHandle)
1013+
public async Task GetErrorHandledTask(Task taskToHandle, TaskCompletionSource completionSource = null)
10211014
{
10221015
try
10231016
{
@@ -1027,6 +1020,10 @@ public async Task GetErrorHandledTask(Task taskToHandle)
10271020
{
10281021
HandledExceptions.Add(ex);
10291022
}
1023+
finally
1024+
{
1025+
completionSource?.SetResult();
1026+
}
10301027
}
10311028
}
10321029
}

0 commit comments

Comments
 (0)