Skip to content

Commit

Permalink
Fix TestClock.sleep hang when sleeping until deadline that is equal t…
Browse files Browse the repository at this point in the history
…o now (#22)
  • Loading branch information
bobergj authored Sep 26, 2023
1 parent d1fd837 commit 2f8a1b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Clocks/TestClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
let id = UUID()
do {
let stream: AsyncThrowingStream<Never, Error>? = self.lock.sync {
guard deadline >= self.now
guard deadline > self.now
else {
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions Tests/ClocksTests/TestClocksTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ final class TestClockTests: XCTestCase, @unchecked Sendable {
XCTAssertEqual(checkIsFinished, true)
}

func testSleepUntilExactlyNow() async throws {
let duration: Duration = .seconds(1)
let deadline = clock.now.advanced(by: duration)
await clock.advance(by: duration)
try await clock.sleep(until: deadline)
}

func testAdvanceWithReentrantUnitsOfWork() async throws {
let task = Task {
var count = 0
Expand Down

0 comments on commit 2f8a1b0

Please sign in to comment.