From 11c56e264afd63d4c800ebb444f1aac45b83dfd6 Mon Sep 17 00:00:00 2001 From: Bogdan Belogurov Date: Fri, 14 Feb 2025 17:21:13 +0100 Subject: [PATCH] entities: Remove AssertionFailure.taskExplicitlyCanceled case We need to be able to cancel the task ourselves and test this logic. The current assertion does not allow us to do this. --- Sources/Entities/AsyncStub.swift | 12 ++---------- Sources/FailureReporter/AssertionFailure.swift | 3 --- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Sources/Entities/AsyncStub.swift b/Sources/Entities/AsyncStub.swift index 6237b0a..537150e 100644 --- a/Sources/Entities/AsyncStub.swift +++ b/Sources/Entities/AsyncStub.swift @@ -27,11 +27,7 @@ extension AsyncStub: AsyncInvokable { .handleFatalError(.testDoubleTypeMismatch(expected: "Async", received: "Throwing"), location: nil) } - do { - try await Task.sleep(nanoseconds: delayInNanoseconds) - } catch { - FailureReporter.handler.handleFatalError(.taskExplicitlyCanceled, location: nil) - } + try? await Task.sleep(nanoseconds: delayInNanoseconds) return result } } @@ -41,11 +37,7 @@ extension AsyncStub: ThrowingAsyncInvokable { @Sendable func throwingAsyncInvoke(arguments: [Any]) async throws -> Value { - do { - try await Task.sleep(nanoseconds: delayInNanoseconds) - } catch { - FailureReporter.handler.handleFatalError(.taskExplicitlyCanceled, location: nil) - } + try await Task.sleep(nanoseconds: delayInNanoseconds) switch stubbedValue { case .success(let value): diff --git a/Sources/FailureReporter/AssertionFailure.swift b/Sources/FailureReporter/AssertionFailure.swift index 897f06c..e514ef6 100644 --- a/Sources/FailureReporter/AssertionFailure.swift +++ b/Sources/FailureReporter/AssertionFailure.swift @@ -9,7 +9,6 @@ public enum AssertionFailure: Error { case expectedToBeCalledOnce(calledCount: Int) case expectedToBeCalledTimes(expectedCount: Int, calledCount: Int) case testDoubleTypeMismatch(expected: String, received: String) - case taskExplicitlyCanceled } extension AssertionFailure { @@ -34,8 +33,6 @@ extension AssertionFailure { return "Expected to be called \(expectedCount) time(s) but called \(calledCount) time(s)" case .testDoubleTypeMismatch(let expected, let received): return "Expected closure to be type of \(expected), received \(received)" - case .taskExplicitlyCanceled: - return "Task explicitly canceled" } } }