Skip to content

Commit

Permalink
Fix flakey user indicator controller tests; switch them over to the d…
Browse files Browse the repository at this point in the history
…eferred fulfillment.
  • Loading branch information
stefanceriu committed Jan 28, 2025
1 parent 7ad0aaa commit c94e484
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions UnitTests/Sources/UserIndicatorControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UserIndicatorControllerTests: XCTestCase {
XCTAssertEqual(indicatorController.indicatorQueue.count, 0)
}

func testChainedPresentation() {
func testChainedPresentation() async throws {
indicatorController.minimumDisplayDuration = 0.25
indicatorController.nonPersistentDisplayDuration = 2.5

Expand All @@ -52,47 +52,44 @@ class UserIndicatorControllerTests: XCTestCase {

XCTAssertEqual(indicatorController.activeIndicator?.id, "Third")

let expectation = expectation(description: "Waiting for last indicator to be dismissed")
DispatchQueue.main.asyncAfter(deadline: .now() + indicatorController.nonPersistentDisplayDuration) {
expectation.fulfill()
let fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for last indicator to be dismissed") { indicator in
indicator?.id == "Second"
}

waitForExpectations(timeout: 5.0)
try await fulfillment.fulfill()

XCTAssertEqual(indicatorController.indicatorQueue.count, 2)
XCTAssertEqual(indicatorController.activeIndicator?.id, "Second")
}

func testMinimumDisplayDuration() {
func testMinimumDisplayDuration() async throws {
indicatorController.minimumDisplayDuration = 0.25
indicatorController.nonPersistentDisplayDuration = 2.5

indicatorController.submitIndicator(.init(id: "First", title: ""))
indicatorController.submitIndicator(.init(id: "Second", title: ""))
indicatorController.submitIndicator(.init(id: "Third", title: ""))

indicatorController.retractIndicatorWithId("Second")

XCTAssertEqual(indicatorController.indicatorQueue.count, 3)

let dismissalExpectation = expectation(description: "Waiting for minimum display duration to pass")
DispatchQueue.main.asyncAfter(deadline: .now() + indicatorController.minimumDisplayDuration) {
dismissalExpectation.fulfill()
var fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for minimum display duration to pass") { indicator in
indicator?.id == "First"
}

waitForExpectations(timeout: 5.0)
indicatorController.retractIndicatorWithId("Second")

XCTAssertEqual(indicatorController.indicatorQueue.count, 2)
XCTAssertEqual(indicatorController.activeIndicator?.id, "Third")
try await fulfillment.fulfill()

let dismissalExpectation2 = expectation(description: "Waiting for last indicator to be dismissed")
DispatchQueue.main.asyncAfter(deadline: .now() + indicatorController.nonPersistentDisplayDuration) {
dismissalExpectation2.fulfill()
XCTAssertEqual(indicatorController.indicatorQueue.count, 1)
XCTAssertEqual(indicatorController.activeIndicator?.id, "First")

fulfillment = deferFulfillment(indicatorController.$activeIndicator, message: "Waiting for last indicator to be dismissed") { indicator in
indicator == nil
}

waitForExpectations(timeout: 5.0)
try await fulfillment.fulfill()

XCTAssertEqual(indicatorController.indicatorQueue.count, 1)
XCTAssertEqual(indicatorController.activeIndicator?.id, "First")
XCTAssertEqual(indicatorController.indicatorQueue.count, 0)
XCTAssertNil(indicatorController.activeIndicator)
}
}

0 comments on commit c94e484

Please sign in to comment.