chore: make NetworkService sendable - WPB-24336#4483
chore: make NetworkService sendable - WPB-24336#4483
Conversation
…ove-sendability-WPB-8907
There was a problem hiding this comment.
Pull request overview
This PR updates WireNetwork’s NetworkService to participate in Swift Concurrency by conforming to Sendable (@unchecked), and refactors session setup to remove the error-prone post-init configure(with:) step by injecting URLSession creation via an initializer factory closure.
Changes:
- Make
NetworkServiceProtocolSendableand markNetworkServiceas@unchecked Sendable. - Replace
configure(with:)with an initializer parametermakeURLSessionand update production factories/builders accordingly. - Update WireNetwork unit tests/helpers to construct
NetworkServiceusing the new initializer.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSessionBuilder.swift | Switches REST/websocket/blacklist NetworkService creation to the new makeURLSession initializer pattern. |
| WireNetwork/Tests/WireNetworkTests/Network/NetworkService/NetworkServiceTests.swift | Updates NetworkService test setup to inject a mock session via makeURLSession. |
| WireNetwork/Tests/WireNetworkTests/Network/APIService/APIServiceTests.swift | Updates API service tests to use the new NetworkService initializer. |
| WireNetwork/Tests/WireNetworkTests/Helpers/RequestSnapshotter.swift | Updates test helper to construct NetworkService using makeURLSession. |
| WireNetwork/Tests/WireNetworkTests/Authentication/AuthenticationManagerTests.swift | Updates auth manager tests to use the new NetworkService initializer. |
| WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift | Introduces Sendable conformance and replaces configure(with:) with makeURLSession. |
| WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService+Make.swift | Updates factory helpers to build sessions through makeURLSession. |
| WireNetwork/Sources/WireNetwork/Assembly.swift | Updates assembly wiring for apiNetworkService to use makeURLSession. |
| WireAuthentication/Sources/WireAuthentication/NetworkService+Factory.swift | Updates authentication factory to use the new NetworkService initializer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift
Show resolved
Hide resolved
WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift
Outdated
Show resolved
Hide resolved
WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift
Show resolved
Hide resolved
WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift
Show resolved
Hide resolved
Test Results1 581 tests 1 581 ✅ 1m 58s ⏱️ Results for commit 0ad7e88. ♻️ This comment has been updated with latest results. Summary: workflow run #23738810497 |
…ove-sendability-WPB-8907
…ove-sendability-WPB-8907
…ove-sendability-WPB-8907
| XCTAssertEqual(receivedRequest.url?.absoluteString, backendURL.appendingPathComponent("/foo").absoluteString) | ||
| } | ||
|
|
||
| // MARK: - URLAuthenticationChallenge |
There was a problem hiding this comment.
moved to NetworkServiceSessionDelegateTests.swift
| URLCredential(user: "user", password: "password", persistence: .none) | ||
| } | ||
|
|
||
| static func makeAuthenticationChallenge( |
There was a problem hiding this comment.
also moved to NetworkServiceSessionDelegateTests.swift
…sendability-WPB-8907
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WireAuthentication/Sources/WireAuthentication/NetworkService+Factory.swift
Outdated
Show resolved
Hide resolved
WireNetwork/Sources/WireNetwork/Network/NetworkService/NetworkService.swift
Show resolved
Hide resolved
wire-ios-sync-engine/Source/UserSession/ZMUserSession/ZMUserSessionBuilder.swift
Outdated
Show resolved
Hide resolved
samwyndham
left a comment
There was a problem hiding this comment.
Great! Interestingly I think there was another reason we needed to pass in the URLSession after the NetworkService was created but that doesn't seem to be the case now.
…ove-sendability-WPB-8907
|



Issue
This PR makes
NetworkServiceconform toSendableby extracting theURLSession's delegate. AnURLSessionConfigurationargument is used for creating an url session in production code and for mocks.Checklist
[WPB-XXX].UI accessibility checklist
If your PR includes UI changes, please utilize this checklist: