Skip to content

Commit 70c5db8

Browse files
mapbox-github-ci-writer-5[bot]evil159
authored andcommitted
[Backport release/v0.18] fix flaky test (#9052)
Backport 16f46a5e0ce4a58f1313526347bafd164a242123 from #8989. Co-authored-by: Roman Laitarenko <roman.laitarenko@mapbox.com> GitOrigin-RevId: 42a5f6b6424fe46c58a44a4bd675b01864bd77f3
1 parent 342bd6e commit 70c5db8

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

Tests/MapboxMapsTests/Foundation/MapboxMapTests.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,24 @@ final class MapboxMapTests: XCTestCase {
369369
XCTAssertEqual(mapboxMap.__testingMap.getCenterAltitudeMode(), .sea)
370370
}
371371

372-
func testLoadStyleHandlerIsInvokedExactlyOnce() throws {
373-
let completionIsCalledOnce = expectation(description: "loadStyle completion should be called once")
372+
func testLoadStyle() throws {
373+
let completionIsCalledOncePerSubscriber = expectation(
374+
description: "loadStyle completion should be called once per subscriber"
375+
)
376+
completionIsCalledOncePerSubscriber.expectedFulfillmentCount = 2
377+
let styleJSON = String.testStyleJSON()
374378

379+
// this load should be cancelled to the succeeding load,
380+
// but the completion is expected to be invoked after successfull style load
375381
mapboxMap.loadStyle(.dark) { _ in
376-
completionIsCalledOnce.fulfill()
382+
completionIsCalledOncePerSubscriber.fulfill()
377383
}
378-
379-
// Ensure loadStyle subscription is registered before firing events
380-
// by dispatching event sends asynchronously on the main queue
381-
let interval = EventTimeInterval(begin: .init(), end: .init())
382-
DispatchQueue.main.async {
383-
self.events.onStyleLoaded.send(StyleLoaded(timeInterval: interval))
384-
self.events.onStyleLoaded.send(StyleLoaded(timeInterval: interval))
384+
mapboxMap.loadStyle(styleJSON) { _ in
385+
completionIsCalledOncePerSubscriber.fulfill()
385386
}
387+
XCTAssertEqual(mapboxMap.styleJSON, styleJSON)
386388

387-
waitForExpectations(timeout: 5.0)
389+
waitForExpectations(timeout: 3.0)
388390
}
389391

390392
func testEvents() {

Tests/MapboxMapsTests/Style/Fixtures/Fixtures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ internal extension String {
157157
41.8781
158158
],
159159
"zoom": 12,
160-
"sources": [Any](),
161-
"layers": [Any]()
160+
"sources": [String: Any](),
161+
"layers": [String: Any]()
162162
]
163163
return ValueConverter.toJson(forValue: styleJSONObject)
164164
}

0 commit comments

Comments
 (0)