Attempt fix for unreliable tests

This commit is contained in:
Stefan Ceriu
2022-07-22 14:33:48 +03:00
committed by Stefan Ceriu
parent 2f69c99782
commit b0bbbfc1d7
2 changed files with 10 additions and 8 deletions
@@ -16,7 +16,8 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx
var isVerified = false var isVerified = false
func requestVerification() async -> Result<Void, SessionVerificationControllerProxyError> { func requestVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
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)) callbacks.send(.receivedVerificationData(Self.emojis))
} }
@@ -24,7 +25,8 @@ struct MockSessionVerificationControllerProxy: SessionVerificationControllerProx
} }
func approveVerification() async -> Result<Void, SessionVerificationControllerProxyError> { func approveVerification() async -> Result<Void, SessionVerificationControllerProxyError> {
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 2.0) { Task.detached {
try await Task.sleep(nanoseconds: 2_000_000_000)
callbacks.send(.finished) callbacks.send(.finished)
} }
@@ -98,16 +98,16 @@ class UserIndicatorTests: XCTestCase {
// MARK: - Dismissal // MARK: - Dismissal
func testDismissAfterTimeout() { func testDismissAfterTimeout() {
let interval: TimeInterval = 0.01 let indicator = makeIndicator(dismissal: .timeout(1.0))
let indicator = makeIndicator(dismissal: .timeout(interval))
indicator.start() indicator.start()
let exp = expectation(description: "") let expectation = expectation(description: "Wait for the indicator to dismiss")
DispatchQueue.main.asyncAfter(deadline: .now() + interval) { DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
exp.fulfill() expectation.fulfill()
} }
waitForExpectations(timeout: 1)
wait(for: [expectation], timeout: 5.0)
XCTAssertEqual(indicator.state, .completed) XCTAssertEqual(indicator.state, .completed)
} }