From b0bbbfc1d797bb058064a9bf2ba33748b3399620 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 22 Jul 2022 14:33:48 +0300 Subject: [PATCH] Attempt fix for unreliable tests --- .../MockSessionVerificationControllerProxy.swift | 6 ++++-- .../Sources/UserIndicators/UserIndicatorTests.swift | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift b/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift index 59549a984..09374fad6 100644 --- a/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift +++ b/ElementX/Sources/Services/SessionVerification/MockSessionVerificationControllerProxy.swift @@ -16,7 +16,8 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx var isVerified = false func requestVerification() async -> Result { - DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 2.0) { + Task.detached { + try await Task.sleep(nanoseconds: 2_000_000_000) callbacks.send(.receivedVerificationData(Self.emojis)) } @@ -24,7 +25,8 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx } func approveVerification() async -> Result { - DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 2.0) { + Task.detached { + try await Task.sleep(nanoseconds: 2_000_000_000) callbacks.send(.finished) } diff --git a/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift b/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift index 1717b65dd..948e70461 100644 --- a/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift +++ b/UnitTests/Sources/UserIndicators/UserIndicatorTests.swift @@ -98,16 +98,16 @@ class UserIndicatorTests: XCTestCase { // MARK: - Dismissal func testDismissAfterTimeout() { - let interval: TimeInterval = 0.01 - let indicator = makeIndicator(dismissal: .timeout(interval)) + let indicator = makeIndicator(dismissal: .timeout(1.0)) indicator.start() - let exp = expectation(description: "") - DispatchQueue.main.asyncAfter(deadline: .now() + interval) { - exp.fulfill() + let expectation = expectation(description: "Wait for the indicator to dismiss") + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + expectation.fulfill() } - waitForExpectations(timeout: 1) + + wait(for: [expectation], timeout: 5.0) XCTAssertEqual(indicator.state, .completed) }