diff --git a/Package.resolved b/Package.resolved index 727e07b3..d9770c86 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,23 +1,5 @@ { "pins" : [ - { - "identity" : "swift-async-algorithms", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-async-algorithms", - "state" : { - "branch" : "cf70e78", - "revision" : "cf70e78632e990cd041fef21044e54fa5fdd1c56" - } - }, - { - "identity" : "swift-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections.git", - "state" : { - "revision" : "f504716c27d2e5d4144fa4794b12129301d17729", - "version" : "1.0.3" - } - }, { "identity" : "swift-concurrency-extras", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 68a5cde2..f09944fd 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,6 @@ 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", from: "1.0.0"), .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"), @@ -36,7 +35,6 @@ let package = Package( name: "ClocksTests", dependencies: [ "Clocks", - .product(name: "AsyncAlgorithms", package: "swift-async-algorithms"), ] ), ] diff --git a/Tests/ClocksTests/AsyncAlgorithmsTests.swift b/Tests/ClocksTests/AsyncAlgorithmsTests.swift deleted file mode 100644 index aa36455c..00000000 --- a/Tests/ClocksTests/AsyncAlgorithmsTests.swift +++ /dev/null @@ -1,168 +0,0 @@ -import AsyncAlgorithms -import Clocks -import XCTest - -@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) -final class AsyncAlgorithmsTests: XCTestCase, @unchecked Sendable { - let clock = TestClock() - var erasedClock: AnyClock { - AnyClock(self.clock) - } - - override func tearDown() async throws { - try await super.tearDown() - try await self.clock.checkSuspension() - } - - func testTimer() async { - let timer = AsyncTimerSequence(interval: .seconds(1), clock: self.erasedClock) - .prefix(10) - - let ticks = ActorIsolated(0) - let task = Task { - for await _ in timer { - await ticks.withValue { $0 += 1 } - } - } - - await self.clock.advance(by: .seconds(1)) - var actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 1) - - await self.clock.advance(by: .seconds(4)) - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 5) - - await self.clock.advance(by: .seconds(5)) - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 10) - - await self.clock.run() - await task.value - XCTAssertEqual(actualTicks, 10) - } - - func testDebounce() async throws { - let (stream, continuation) = AsyncStream.streamWithContinuation() - - let ticks = ActorIsolated(0) - let task = Task { - for await _ in stream.debounce(for: .seconds(1), clock: self.erasedClock) { - await ticks.withValue { $0 += 1 } - } - } - - // Nothing is emitted immediately after the base stream emits. - continuation.yield() - await self.clock.advance() - var actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 0) - - // Nothing is emitted after half a second. - await self.clock.advance(by: .milliseconds(500)) - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 0) - - // Ping the base stream again. - continuation.yield() - - // Nothing is emitted after another half a second. - await self.clock.advance(by: .milliseconds(500)) - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 0) - - // Only after waiting a full second after the base emitted do we get an emission. - await self.clock.advance(by: .milliseconds(500)) - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 1) - - // Pending emission is discarded if base stream finishes. - continuation.yield() - continuation.finish() - await self.clock.run() - await task.value - XCTAssertEqual(actualTicks, 1) - } - - func testThrottle() async throws { - let (stream, continuation) = AsyncStream.streamWithContinuation() - - let ticks = ActorIsolated(0) - let task = Task { - for await _ in stream.throttle(for: .seconds(1), clock: self.erasedClock) { - await ticks.withValue { $0 += 1 } - } - } - - // First base stream value is emitted immediately. - continuation.yield() - await self.clock.advance() - var actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 1) - - // Ping the base stream after half a second. - await self.clock.advance(by: .milliseconds(500)) - continuation.yield() - - // Nothing is emitted after another half a second. - await self.clock.advance() - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 1) - - // Ping the base stream after another half a second. - await self.clock.advance(by: .milliseconds(500)) - continuation.yield() - - // Value is emitted - await self.clock.advance() - actualTicks = await ticks.value - XCTAssertEqual(actualTicks, 2) - - // Pending emission is discarded if base stream finishes. - continuation.yield() - continuation.finish() - await self.clock.run() - await task.value - XCTAssertEqual(actualTicks, 2) - } - - func testSelect_First() async throws { - let task = Task { - await Task.select([ - Task { - try await self.clock.sleep(for: .seconds(1)) - return 1 - }, - Task { - try await self.clock.sleep(for: .seconds(2)) - return 2 - }, - ]) - } - - await self.clock.advance(by: .seconds(2)) - - let winner = try await task.value.value - XCTAssertEqual(winner, 1) - } - - func testSelect_Second() async throws { - let task = Task { - await Task.select([ - Task { - try await self.clock.sleep(for: .seconds(2)) - return 1 - }, - Task { - try await self.clock.sleep(for: .seconds(1)) - return 2 - }, - ]) - } - - await self.clock.advance(by: .seconds(2)) - - let winner = try await task.value.value - XCTAssertEqual(winner, 2) - } -} diff --git a/Tests/ClocksTests/TestClocksTests.swift b/Tests/ClocksTests/TestClocksTests.swift index 372ac2af..5e1e1ee9 100644 --- a/Tests/ClocksTests/TestClocksTests.swift +++ b/Tests/ClocksTests/TestClocksTests.swift @@ -1,4 +1,3 @@ -import AsyncAlgorithms import Clocks import XCTest @@ -100,8 +99,8 @@ final class TestClockTests: XCTestCase, @unchecked Sendable { #endif func testRunMultipleUnitsOfWork() async { - let timer = AsyncTimerSequence(interval: .seconds(1), clock: self.clock) - .prefix(10) + let timer = clock.timer(interval: .seconds(1)) + .prefix(10) let task = Task { var ticks = 0 diff --git a/Tests/ClocksTests/UnimplementedClockTests.swift b/Tests/ClocksTests/UnimplementedClockTests.swift index 03eba786..951b3ced 100644 --- a/Tests/ClocksTests/UnimplementedClockTests.swift +++ b/Tests/ClocksTests/UnimplementedClockTests.swift @@ -1,5 +1,4 @@ #if DEBUG && canImport(Darwin) - import AsyncAlgorithms import Clocks import XCTest