Skip to content

Commit 994ad10

Browse files
evil159github-actions[bot]
authored andcommitted
fix flaky test (#8989)
This PR addresses flakiness(likely caused by network) with `testLoadStyleHandlerIsInvokedExactlyOnce` test. Looking at the test I'm not sure what scenario is being tested, as with adoption of runtime styling callbacks `onStyleLoaded` event has nothing to do with style loaded completion invocation. I replaced the test with more fitting test for current setup. In the test I issue two style load requests one after another - my expectation is that the completion handler is invoked once per subscriber. cc @mapbox/maps-ios GitOrigin-RevId: 16f46a5e0ce4a58f1313526347bafd164a242123
1 parent 34b2de6 commit 994ad10

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

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)