[tests] Detect when we couldn't create a second background session.#24878
[tests] Detect when we couldn't create a second background session.#24878rolfbjarne merged 3 commits intomainfrom
Conversation
When disposing an NSUrlSessionHandler backed by a background NSUrlSession and immediately creating a new handler with the same background session identifier, the new session could fail with 'Task created in a session that has been invalidated'. This happened because InvalidateAndCancel() is asynchronous - it marks the session for invalidation but doesn't wait for it to complete. Apple reuses the same native session object for background sessions with the same identifier, so creating a new session before invalidation completes returns the already-invalidated session. Fix by detecting this scenario in the test, and marking the test as inconclusive. Fixes #24376 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates an HTTP-related monotouch test to treat a specific Objective-C failure mode as inconclusive when disposing and immediately recreating a background NSUrlSessionHandler with the same background session identifier.
Changes:
- Detects the ObjCException message “Task created in a session that has been invalidated” during the second request.
- Marks the test inconclusive for this scenario, documenting the likely root cause and alternative fixes.
You can also share your feedback on Copilot code review. Take the survey.
tests/monotouch-test/System.Net.Http/NSUrlSessionHandlerTest.cs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #60da9a3] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 13 tests failed, 143 tests passed. Failures❌ linker tests11 tests failed, 33 tests passed.Failed tests
|
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #23dc865] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #23dc865] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #23dc865] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #23dc865] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 156 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
When disposing an NSUrlSessionHandler backed by a background NSUrlSession and immediately creating a new handler with the same background session identifier, the new session could fail with 'Task created in a session that has been invalidated'.
This happened because InvalidateAndCancel() is asynchronous - it marks the session for invalidation but doesn't wait for it to complete. Apple reuses the same native session object for background sessions with the same identifier, so creating a new session before invalidation completes returns the already-invalidated session.
Fix by detecting this scenario in the test, and marking the test as inconclusive.
Fixes #24376