Skip to content

Commit f93f952

Browse files
committed
clock test
1 parent 1896b58 commit f93f952

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Tests/TimeoutTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ struct TimeoutTests {
119119
try await TestActor("Fish").returningValue(after: 0.1, before: .now)
120120
}
121121
}
122+
123+
@Test
124+
func returnsValueWithClock_beforeDeadlineExpires() async throws {
125+
#expect(
126+
try await withThrowingTimeout(after: .now + .seconds(2), clock: ContinuousClock()) {
127+
"Fish"
128+
} == "Fish"
129+
)
130+
}
131+
132+
@Test
133+
func throwsErrorWithClock_WhenDeadlineExpires() async {
134+
await #expect(throws: TimeoutError.self) {
135+
try await withThrowingTimeout(after: .now, clock: ContinuousClock()) {
136+
try await Task.sleep(for: .seconds(2))
137+
}
138+
}
139+
}
122140
}
123141

124142
public struct NonSendable<T> {

0 commit comments

Comments
 (0)