File tree Expand file tree Collapse file tree
test/NuGet.Core.Tests/NuGet.PackageManagement.Test Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -59,13 +59,21 @@ public async Task ResolverGather_TimeoutFromPrimaryRepositoryThrows()
5959 ResolutionContext = new ResolutionContext ( )
6060 } ;
6161
62- var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 500 ) ) ;
62+ using var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 500 ) ) ;
6363
6464 // Act and Assert
65- await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) =>
65+ // Under CPU contention, cancellation checks in the main loop may fire
66+ // before worker tasks convert OperationCanceledException to
67+ // InvalidOperationException. Both outcomes correctly indicate failure.
68+ Exception exception = await Record . ExceptionAsync ( async ( ) =>
6669 {
6770 await ResolverGather . GatherAsync ( context , cts . Token ) ;
6871 } ) ;
72+
73+ Assert . NotNull ( exception ) ;
74+ Assert . True (
75+ exception is InvalidOperationException || exception is OperationCanceledException ,
76+ $ "Expected InvalidOperationException or OperationCanceledException but got { exception . GetType ( ) . Name } : { exception . Message } ") ;
6977 }
7078
7179 [ Fact ]
@@ -108,7 +116,7 @@ public async Task ResolverGather_TimeoutFromSecondaryRepositoryIgnored()
108116 ResolutionContext = new ResolutionContext ( )
109117 } ;
110118
111- var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 5000 ) ) ;
119+ using var cts = new CancellationTokenSource ( TimeSpan . FromMilliseconds ( 5000 ) ) ;
112120
113121 // Act
114122 var results = await ResolverGather . GatherAsync ( context , cts . Token ) ;
You can’t perform that action at this time.
0 commit comments