Skip to content

Commit e502dda

Browse files
tatiana-yangithub-actions[bot]
authored andcommitted
[ios][tests] Remove multiple tilestores usage from tests, cleanup between tests.
GitOrigin-RevId: 32d18b02133cab313f28e21852e560fabdce1ec3
1 parent d32c6c1 commit e502dda

4 files changed

Lines changed: 55 additions & 25 deletions

File tree

Tests/MapboxMapsTests/Integration Tests/MapViewIntegrationTestCase.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ internal class MapViewIntegrationTestCase: IntegrationTestCase {
1717

1818
dataPathURL = try temporaryCacheDirectory()
1919

20-
// allow multiple tilestore folders
21-
let ss = SettingsServiceFactory.getInstance(storageType: SettingsServiceStorageType.nonPersistent)
22-
let result = ss.set(key: "com.mapbox.common.tilestore.allow_multiple", value: true)
23-
switch result {
24-
case .success:
25-
print("Allowed multiple tilestores")
26-
27-
case .failure(let error):
28-
print("Error allowing multiple tilestores: \(String(describing: error.errorDescription))")
29-
}
30-
3120
guard let window = window,
3221
let rootView = rootViewController?.view else {
3322
XCTFail("No valid UIWindow or root view controller")

Tests/MapboxMapsTests/Integration Tests/OfflineManagerIntegrationTests.swift

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ final class OfflineManagerIntegrationTestCase: IntegrationTestCase {
1919
func setupTileStoreAndOfflineManager() throws {
2020
tileRegionId = "tile-region-\(name)"
2121

22-
// TileStore
23-
tileStorePathURL = try temporaryCacheDirectory()
24-
25-
// Cache the created tile store
26-
tileStore = TileStore.shared(for: tileStorePathURL)
22+
tileStore = TileStore.default
23+
let ss = SettingsServiceFactory.getInstance(storageType: SettingsServiceStorageType.nonPersistent)
24+
let pathResult = ss.getForKey("com.mapbox.common.tilestore.location")
25+
tileStorePathURL = pathResult.isValue() ? (pathResult.value as? String).flatMap({ URL(string: $0) }) : nil
2726

2827
MapboxMapsOptions.dataPath = tileStorePathURL
2928
MapboxMapsOptions.tileStore = tileStore
@@ -45,19 +44,33 @@ final class OfflineManagerIntegrationTestCase: IntegrationTestCase {
4544
}
4645

4746
override func tearDownWithError() throws {
47+
// Remove tile region before releasing the tile store to prevent
48+
// stale regions from leaking into subsequent tests.
49+
if let tileStore = tileStore, !tileRegionId.isEmpty {
50+
let removeExpectation = expectation(description: "Remove tile region")
51+
tileStore.removeTileRegion(forId: tileRegionId)
52+
// Force eviction of tile data, then restore default quota
53+
tileStore.setOptionForKey(TileStoreOptions.diskQuota, value: 0)
54+
tileStore.allTileRegions { _ in
55+
removeExpectation.fulfill()
56+
}
57+
wait(for: [removeExpectation], timeout: 10.0)
58+
tileStore.setOptionForKey(TileStoreOptions.diskQuota, value: NSNull())
59+
}
60+
4861
tileRegionLoadOptions = nil
4962
offlineManager = nil
5063
tileStore = nil
51-
clearMapData()
52-
try super.tearDownWithError()
53-
}
5464

55-
private func clearMapData() {
56-
let expectation = self.expectation(description: "Clear map data")
65+
let clearDataExpectation = expectation(description: "Clear map data")
5766
MapboxMapsOptions.clearData { _ in
58-
expectation.fulfill()
67+
clearDataExpectation.fulfill()
5968
}
60-
wait(for: [expectation], timeout: 10.0)
69+
wait(for: [clearDataExpectation], timeout: 10.0)
70+
71+
tileStorePathURL = nil
72+
73+
try super.tearDownWithError()
6174
}
6275

6376
// MARK: Test Cases

Tests/MapboxMapsTests/MigrationGuide/OfflineGuideIntegrationTests.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,32 @@ class OfflineGuideIntegrationTests: XCTestCase {
1515
override func setUpWithError() throws {
1616
try super.setUpWithError()
1717

18-
tileStorePathURL = try temporaryCacheDirectory()
19-
tileStore = TileStore.shared(for: tileStorePathURL)
18+
tileStore = TileStore.default
19+
let ss = SettingsServiceFactory.getInstance(storageType: SettingsServiceStorageType.nonPersistent)
20+
let pathResult = ss.getForKey("com.mapbox.common.tilestore.location")
21+
tileStorePathURL = pathResult.isValue() ? (pathResult.value as? String).flatMap({ URL(string: $0) }) : nil
2022
}
2123

2224
override func tearDownWithError() throws {
2325
try super.tearDownWithError()
2426

27+
// Remove all tile regions to prevent stale regions from leaking
28+
// into subsequent tests.
29+
let cleanupExpectation = expectation(description: "Tile regions cleanup")
30+
tileStore.allTileRegions { result in
31+
if case let .success(regions) = result {
32+
for region in regions {
33+
self.tileStore.removeTileRegion(forId: region.id)
34+
}
35+
}
36+
self.tileStore.setOptionForKey(TileStoreOptions.diskQuota, value: 0)
37+
self.tileStore.setOptionForKey(TileStoreOptions.diskQuota, value: NSNull())
38+
cleanupExpectation.fulfill()
39+
}
40+
wait(for: [cleanupExpectation], timeout: 10.0)
41+
2542
tileStore = nil
43+
MapboxMapsOptions.tileStore = nil
2644
}
2745

2846
// Test StylePackLoadOptions

Tests/MapboxMapsTests/Style/AttributionTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import UIKit
55

66
class AttributionTests: XCTestCase {
77

8+
override func tearDownWithError() throws {
9+
let clearDataExpectation = expectation(description: "Clear map data")
10+
MapboxMapsOptions.clearData { _ in
11+
clearDataExpectation.fulfill()
12+
}
13+
wait(for: [clearDataExpectation], timeout: 10.0)
14+
MapboxMapsOptions.tileStore = nil
15+
try super.tearDownWithError()
16+
}
17+
818
func testActionableAttributionParsing() {
919
let attributionsHTML = """
1020
<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\" title=\"Mapbox\" aria-label=\"Mapbox\" role=\"listitem\">&copy; Mapbox</a>

0 commit comments

Comments
 (0)