-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow settings migration from packet tunnel
- Loading branch information
1 parent
b54a6c3
commit 3ec12b7
Showing
8 changed files
with
150 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
ios/MullvadVPNTests/MullvadSettings/MigrationManagerMultiProcessUpgradeTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// MigrationManagerMultiProcessUpgradeTests.swift | ||
// MullvadVPNTests | ||
// | ||
// Created by Marco Nikic on 2024-10-03. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
@testable import MullvadMockData | ||
@testable import MullvadREST | ||
@testable import MullvadSettings | ||
@testable import MullvadTypes | ||
import XCTest | ||
|
||
extension MigrationManagerTests { | ||
func testMigrationDoesNothingIfAnotherProcessIsRunningUpdates() throws { | ||
let hostProcess = DispatchQueue(label: "net.tests.HostMigration") | ||
let packetTunnelProcess = DispatchQueue(label: "net.tests.PacketTunnelMigration") | ||
let osakaRelayConstraints = RelayConstraints( | ||
exitLocations: .only(UserSelectedRelays(locations: [.city("jp", "osa")])) | ||
) | ||
var settingsV1 = TunnelSettingsV1() | ||
settingsV1.relayConstraints = osakaRelayConstraints | ||
|
||
try write(settings: settingsV1, version: SchemaVersion.v1.rawValue, in: Self.store) | ||
|
||
let backgroundMigrationExpectation = expectation(description: "Migration from packet tunnel") | ||
let foregroundMigrationExpectation = expectation(description: "Migration from host") | ||
var migrationHappenedInPacketTunnel = false | ||
var migrationHappenedInHost = false | ||
|
||
packetTunnelProcess.async { [unowned self] in | ||
manager.migrateSettings(store: MigrationManagerTests.store) { backgroundMigrationResult in | ||
if case .success = backgroundMigrationResult { | ||
migrationHappenedInPacketTunnel = true | ||
} | ||
backgroundMigrationExpectation.fulfill() | ||
} | ||
} | ||
|
||
hostProcess.async { [unowned self] in | ||
manager.migrateSettings(store: MigrationManagerTests.store) { foregroundMigrationResult in | ||
if case .success = foregroundMigrationResult { | ||
migrationHappenedInHost = true | ||
} | ||
foregroundMigrationExpectation.fulfill() | ||
} | ||
} | ||
|
||
wait(for: [backgroundMigrationExpectation, foregroundMigrationExpectation], timeout: .UnitTest.invertedTimeout) | ||
|
||
// Migration happens either in one process, or the other. | ||
// This check guarantees it didn't happen in both simultaneously. | ||
XCTAssertNotEqual(migrationHappenedInPacketTunnel, migrationHappenedInHost) | ||
let latestSettings = try SettingsManager.readSettings() | ||
XCTAssertEqual(osakaRelayConstraints, latestSettings.relayConstraints) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters