Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various flakey test fixes #3710

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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)
}
}
Loading