Skip to content

Commit 68c3582

Browse files
committed
[tests] Ignore NSUrlSessionHandlerTest.DisposeAndRecreateBackgroundSessionHandler if the background session is in use.
Hopefully fixes this test failure: [FAIL] DisposeAndRecreateBackgroundSessionHandler : Second request exception Expected: null But was: <System.Net.Http.HttpRequestException: Could not communicate with background transfer service ---> Foundation.NSErrorException: Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo={_NSURLErrorRelatedURLSessionTaskErrorKey=( "BackgroundDataTask <FE008EA4-3168-4E2F-B066-9565EEC47E67>.<1>" ), NSLocalizedDescription=Could not communicate with background transfer service, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundDataTask <FE008EA4-3168-4E2F-B066-9565EEC47E67>.<1>} --- End of inner exception stack trace --- at System.Net.Http.NSUrlSessionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /Users/builder/azdo/_work/4/s/macios/src/Foundation/NSUrlSessionHandler.cs:line 595 at System.Net.Http.HttpClient.GetByteArrayAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at MonoTests.System.Net.Http.NSUrlSessionHandlerTest.<>c.<<DisposeAndRecreateBackgroundSessionHandler>b__0_1>d.MoveNext() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs:line 47 --- End of stack trace from previous location --- at TestRuntime.TryRunAsync(TimeSpan timeout, Task startTask, Task completionTask, UIImage imageToShow, Exception& exception) in /Users/builder/azdo/_work/1/s/macios/tests/common/TestRuntime.RunAsync.cs:line 119> at MonoTests.System.Net.Http.NSUrlSessionHandlerTest.DisposeAndRecreateBackgroundSessionHandler() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs:line 60
1 parent 36c83c7 commit 68c3582

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void DisposeAndRecreateBackgroundSessionHandler ()
3737
Assert.Inconclusive ("First request failed or timed out - cannot verify the bug.");
3838
}
3939

40+
IgnoreIfExceptionDueToBackgroundServiceInUseByAnotherProcess (ex);
4041
TestRuntime.IgnoreInCIIfBadNetwork (ex);
4142
Assert.IsNull (ex, "First request exception");
4243

@@ -56,8 +57,26 @@ public void DisposeAndRecreateBackgroundSessionHandler ()
5657
Assert.Fail ("Second request timedout - this indicates the bug is present.");
5758
}
5859

60+
IgnoreIfExceptionDueToBackgroundServiceInUseByAnotherProcess (ex);
5961
TestRuntime.IgnoreInCIIfBadNetwork (ex);
6062
Assert.IsNull (ex, "Second request exception");
6163
}
64+
65+
void IgnoreIfExceptionDueToBackgroundServiceInUseByAnotherProcess (Exception? e)
66+
{
67+
if (e is null)
68+
return;
69+
70+
if (e is not HttpRequestException hre)
71+
return;
72+
73+
if (hre.InnerException is not NSErrorException nee)
74+
return;
75+
76+
if (nee.Code != (nint) NSUrlError.BackgroundSessionInUseByAnotherProcess)
77+
return;
78+
79+
Assert.Ignore ("The background service is in use by another process.");
80+
}
6281
}
6382
}

0 commit comments

Comments
 (0)