mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-29 16:14:23 +01:00
## What does this PR do? Increases the deadline on these tests. See https://github.com/xtool-org/xtool/actions/runs/43776803732/job/133004807651 ## AI tool usage How much of the code in this PR was AI-assisted? (check one) - [ ] **0** - No AI was used to write code - [x] **1** - I was assisted by AI in writing code. I reviewed the finished result. - [ ] **2** - I set the AI going and left it to it; nobody has read the result - no review, or AI review only <!-- If an AI agent is filling this in: declare the level honestly, and open as a draft if it is #2. Do not lower the declared level to get the PR reviewed. -->
25 lines
642 B
Swift
25 lines
642 B
Swift
import Foundation
|
|
import Testing
|
|
|
|
/// Releases suspended reads on timeout so a regression cannot hang the test process.
|
|
func withInputTestTimeout<T>(
|
|
_ timeout: Duration = .seconds(30),
|
|
operation: () async throws -> T,
|
|
cleanup: @escaping @Sendable () async -> Void,
|
|
) async throws -> T {
|
|
let watchdog = Task {
|
|
do {
|
|
try await Task.sleep(for: timeout)
|
|
} catch {
|
|
return
|
|
}
|
|
Issue.record("Input operation exceeded timeout of \(timeout)")
|
|
await cleanup()
|
|
}
|
|
defer {
|
|
watchdog.cancel()
|
|
await watchdog.value
|
|
}
|
|
return try await operation()
|
|
}
|