diff options
| author | Jon Petersson <jon.petersson@mullvad.net> | 2026-01-07 15:55:41 +0100 |
|---|---|---|
| committer | Jon Petersson <jon.petersson@mullvad.net> | 2026-01-09 12:17:44 +0100 |
| commit | 78a3e8a5df1d0b4012a54090660f3f642068684b (patch) | |
| tree | dc244468a0f63591d53e3a48a623b2b17769a55b | |
| parent | fe401c593f2b2176ab31464523a82ca9811bffaf (diff) | |
| download | mullvadvpn-testfetchcurrentlocationidentifier-is-failing-ios-1456.tar.xz mullvadvpn-testfetchcurrentlocationidentifier-is-failing-ios-1456.zip | |
Fix testFetchCurrentLocationIdentifiertestfetchcurrentlocationidentifier-is-failing-ios-1456
6 files changed, 18 insertions, 13 deletions
diff --git a/ios/MullvadREST/ApiHandlers/DefaultLocationService.swift b/ios/MullvadREST/ApiHandlers/DefaultLocationService.swift index 3f3ebc7bd4..997d15882d 100644 --- a/ios/MullvadREST/ApiHandlers/DefaultLocationService.swift +++ b/ios/MullvadREST/ApiHandlers/DefaultLocationService.swift @@ -39,11 +39,11 @@ public struct DefaultLocationService { locations: relayCache.relays.locations ) - let closestRelay = RelaySelector.closestRelay( + let closestRelays = RelaySelector.closestRelays( to: CLLocationCoordinate2D(latitude: serverLocation.latitude, longitude: serverLocation.longitude), using: mappedRelays ) - return closestRelay?.location + return closestRelays.first?.relay.location } } diff --git a/ios/MullvadREST/Relay/RelaySelector+Shadowsocks.swift b/ios/MullvadREST/Relay/RelaySelector+Shadowsocks.swift index 7b91a8e020..de2e3343e2 100644 --- a/ios/MullvadREST/Relay/RelaySelector+Shadowsocks.swift +++ b/ios/MullvadREST/Relay/RelaySelector+Shadowsocks.swift @@ -55,7 +55,7 @@ extension RelaySelector { return mappedBridges.randomElement()?.relay } - return RelaySelector.closestRelay( + return RelaySelector.randomCloseRelay( to: selectedRelay.serverLocation.geoCoordinate, using: mappedBridges ) as? REST.BridgeRelay diff --git a/ios/MullvadREST/Relay/RelaySelector+Wireguard.swift b/ios/MullvadREST/Relay/RelaySelector+Wireguard.swift index d3c1b2b1e4..f4f707e967 100644 --- a/ios/MullvadREST/Relay/RelaySelector+Wireguard.swift +++ b/ios/MullvadREST/Relay/RelaySelector+Wireguard.swift @@ -49,7 +49,7 @@ extension RelaySelector { var relayWithLocation: RelayWithLocation<REST.ServerRelay>? if let referenceLocation { let relay = - closestRelay( + randomCloseRelay( to: CLLocationCoordinate2D( latitude: referenceLocation.latitude, longitude: referenceLocation.longitude), using: relayWithLocations diff --git a/ios/MullvadREST/Relay/RelaySelector.swift b/ios/MullvadREST/Relay/RelaySelector.swift index ebec530549..ccb8aa490f 100644 --- a/ios/MullvadREST/Relay/RelaySelector.swift +++ b/ios/MullvadREST/Relay/RelaySelector.swift @@ -92,10 +92,10 @@ public enum RelaySelector { } } - static func closestRelay( + static func closestRelays( to location: CLLocationCoordinate2D, using relayWithLocations: [RelayWithLocation<some AnyRelay>] - ) -> AnyRelay? { + ) -> [RelayWithDistance<some AnyRelay>] { let relaysWithDistance = relayWithLocations.map { return RelayWithDistance( relay: $0.relay, @@ -110,6 +110,15 @@ public enum RelaySelector { $0.distance < $1.distance }.prefix(5) + return Array(relaysWithDistance) + } + + static func randomCloseRelay( + to location: CLLocationCoordinate2D, + using relayWithLocations: [RelayWithLocation<some AnyRelay>] + ) -> AnyRelay? { + let relaysWithDistance = closestRelays(to: location, using: relayWithLocations) + var greatestDistance = 0.0 relaysWithDistance.forEach { if $0.distance > greatestDistance { @@ -126,8 +135,6 @@ public enum RelaySelector { return closestRelay?.relay ?? relaysWithDistance.randomElement()?.relay } - // MARK: - private - static func parseRawPortRanges(_ rawPortRanges: [[UInt16]]) -> [ClosedRange<UInt16>] { rawPortRanges.compactMap { inputRange -> ClosedRange<UInt16>? in guard inputRange.count == 2 else { return nil } @@ -166,6 +173,8 @@ public enum RelaySelector { return nil } + // MARK: - private + private static func filterByActive<T: AnyRelay>( relays: [RelayWithLocation<T>] ) throws -> [RelayWithLocation<T>] { diff --git a/ios/MullvadRESTTests/DefaultLocationServiceTests.swift b/ios/MullvadRESTTests/DefaultLocationServiceTests.swift index eb205a2348..8d54efd207 100644 --- a/ios/MullvadRESTTests/DefaultLocationServiceTests.swift +++ b/ios/MullvadRESTTests/DefaultLocationServiceTests.swift @@ -15,10 +15,6 @@ class DefaultLocationServiceTests: XCTestCase { private let encoder = JSONEncoder() func testFetchCurrentLocationIdentifier() async throws { - let skipReason = """ - The behavior is currently nondeterministic. Skip until this is fixed. - """ - try XCTSkipIf(true, skipReason) let mockData = try encoder.encode( REST.ServerLocation( country: "USA", diff --git a/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift b/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift index 9f69bc83fc..35da1933fd 100644 --- a/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift +++ b/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift @@ -142,7 +142,7 @@ class RelaySelectorTests: XCTestCase { } let sampleLocation = try XCTUnwrap(sampleRelays.locations["es-mad"]) - let selectedRelay = RelaySelector.closestRelay( + let selectedRelay = RelaySelector.randomCloseRelay( to: CLLocationCoordinate2D(latitude: sampleLocation.latitude, longitude: sampleLocation.longitude), using: relayWithLocations ) |
