From 5d35020ef90a94253da03951c5f997e6acc78988 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 19 Jun 2023 15:07:07 -0700 Subject: [PATCH 1/4] wip --- Package.resolved | 4 ++-- Package.swift | 6 ++++-- Sources/Clocks/ImmediateClock.swift | 1 + Sources/Clocks/Internal/Yield.swift | 19 ------------------- Sources/Clocks/TestClock.swift | 1 + Sources/Clocks/UnimplementedClock.swift | 1 + 6 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 Sources/Clocks/Internal/Yield.swift diff --git a/Package.resolved b/Package.resolved index 89de3670..f875290b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "f821dcbac7cb6913f8e0d1a80496d0ba0199fa81", - "version" : "0.3.0" + "revision" : "4af50b38daf0037cfbab15514a241224c3f62f98", + "version" : "0.8.5" } } ], diff --git a/Package.swift b/Package.swift index 732a57cf..a4e939e7 100644 --- a/Package.swift +++ b/Package.swift @@ -19,15 +19,17 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.3.0"), .package(url: "https://github.com/apple/swift-async-algorithms", revision: "cf70e78"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), + .package(path: "../swift-concurrency-extras"), + .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.8.0"), ], targets: [ .target( name: "Clocks", dependencies: [ - .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay") + .product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"), + .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"), ] ), .testTarget( diff --git a/Sources/Clocks/ImmediateClock.swift b/Sources/Clocks/ImmediateClock.swift index 529cf414..31815308 100644 --- a/Sources/Clocks/ImmediateClock.swift +++ b/Sources/Clocks/ImmediateClock.swift @@ -1,4 +1,5 @@ #if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst)) + import ConcurrencyExtras import Foundation /// A clock that does not suspend when sleeping. diff --git a/Sources/Clocks/Internal/Yield.swift b/Sources/Clocks/Internal/Yield.swift deleted file mode 100644 index e82fe03f..00000000 --- a/Sources/Clocks/Internal/Yield.swift +++ /dev/null @@ -1,19 +0,0 @@ -import Foundation - -extension Task where Success == Failure, Failure == Never { - // NB: We would love if this was not necessary. See this forum post for more information: - // https://forums.swift.org/t/reliably-testing-code-that-adopts-swift-concurrency/57304 - static func megaYield(count: Int = defaultMegaYieldCount) async { - for _ in 0...detached(priority: .background) { await Task.yield() }.value - } - } -} - -let defaultMegaYieldCount = max( - 0, - min( - ProcessInfo.processInfo.environment["TASK_MEGA_YIELD_COUNT"].flatMap(Int.init) ?? 20, - 10_000 - ) -) diff --git a/Sources/Clocks/TestClock.swift b/Sources/Clocks/TestClock.swift index 02db0a37..c2a19abe 100644 --- a/Sources/Clocks/TestClock.swift +++ b/Sources/Clocks/TestClock.swift @@ -1,4 +1,5 @@ #if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst)) + import ConcurrencyExtras import Foundation import XCTestDynamicOverlay diff --git a/Sources/Clocks/UnimplementedClock.swift b/Sources/Clocks/UnimplementedClock.swift index 6fb0bcf9..5b5a210a 100644 --- a/Sources/Clocks/UnimplementedClock.swift +++ b/Sources/Clocks/UnimplementedClock.swift @@ -1,4 +1,5 @@ #if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst)) + import ConcurrencyExtras import Foundation import XCTestDynamicOverlay From 459dc8d7b78e374ac6bd434b35006b546da5cfcb Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 20 Jun 2023 10:05:52 -0700 Subject: [PATCH 2/4] wip --- Sources/Clocks/Shims.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Clocks/Shims.swift b/Sources/Clocks/Shims.swift index 7e82b4a9..5737704d 100644 --- a/Sources/Clocks/Shims.swift +++ b/Sources/Clocks/Shims.swift @@ -1,4 +1,4 @@ -#if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst)) +#if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst)) && swift(<5.9) @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) extension Clock { /// Suspends for the given duration. From b61454516279ef4136785a1dedf4b57e1bd73e4d Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Thu, 13 Jul 2023 13:57:42 -0700 Subject: [PATCH 3/4] wip --- Package.resolved | 9 +++++++++ Package.swift | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index f875290b..57aa1761 100644 --- a/Package.resolved +++ b/Package.resolved @@ -18,6 +18,15 @@ "version" : "1.0.3" } }, + { + "identity" : "swift-concurrency-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pointfreeco/swift-concurrency-extras", + "state" : { + "branch" : "main", + "revision" : "54c807cb9a333aebdd13ab07e8dd5738701d8f2f" + } + }, { "identity" : "swift-docc-plugin", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index a4e939e7..09cd079d 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-async-algorithms", revision: "cf70e78"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), - .package(path: "../swift-concurrency-extras"), + .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", branch: "main"), .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.8.0"), ], targets: [ From 3ff616c5bbac907b40964322e23005d90f7089bb Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 17 Jul 2023 11:11:17 -0700 Subject: [PATCH 4/4] wip --- Package.resolved | 4 ++-- Package.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index 57aa1761..c8d1e356 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-concurrency-extras", "state" : { - "branch" : "main", - "revision" : "54c807cb9a333aebdd13ab07e8dd5738701d8f2f" + "revision" : "ecb065a41bbdd7f64ab2695ffc755ed37c9ff4dc", + "version" : "0.1.0" } }, { diff --git a/Package.swift b/Package.swift index 09cd079d..358ed87a 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/apple/swift-async-algorithms", revision: "cf70e78"), .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), - .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", branch: "main"), + .package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "0.1.0"), .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.8.0"), ], targets: [