Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmuxTests/CLICodexHookTimeoutRegressionTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,18 @@ func waitForFile(_ url: URL, containing expected: String, timeout: TimeInterval)
return false
}

func waitForCondition(timeout: TimeInterval, pollInterval: TimeInterval = 0.02, _ condition: () -> Bool) -> Bool {
/// Polls `condition` while blocking the calling thread with `Thread.sleep`.
///
/// Use it only for conditions a background thread satisfies, such as a socket
/// accumulator or a file a child process writes. It runs no run loop, so on the
/// main thread it starves main-queue and main-actor work and the condition can
/// never become true. Main-thread waits belong in the per-file XCTWaiter
/// helpers, which pump the main queue between polls.
func waitForConditionBlocking(
timeout: TimeInterval,
pollInterval: TimeInterval = 0.02,
_ condition: () -> Bool
) -> Bool {
let deadline = Date().addingTimeInterval(timeout)
while Date() < deadline {
if condition() {
Expand Down
6 changes: 3 additions & 3 deletions cmuxTests/CLICodexHookTimeoutRegressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct CLICodexHookTimeoutRegressionTests {
)
#expect(oldPrompt.status == 0, Comment(rawValue: oldPrompt.stderr))
#expect(oldPrompt.stdout == "{}\n")
#expect(waitForCondition(timeout: 2) {
#expect(waitForConditionBlocking(timeout: 2) {
commands.snapshot().contains { $0.hasPrefix("set_status codex Running ") }
})

Expand All @@ -270,7 +270,7 @@ struct CLICodexHookTimeoutRegressionTests {
)
#expect(currentPrompt.status == 0, Comment(rawValue: currentPrompt.stderr))
#expect(currentPrompt.stdout == "{}\n")
#expect(waitForCondition(timeout: 2) {
#expect(waitForConditionBlocking(timeout: 2) {
let snapshot = commands.snapshot()
return snapshot.contains { $0.hasPrefix("clear_notifications ") }
&& snapshot.contains { $0.hasPrefix("set_status codex Running ") }
Expand All @@ -286,7 +286,7 @@ struct CLICodexHookTimeoutRegressionTests {
)
#expect(staleStop.status == 0, Comment(rawValue: staleStop.stderr))
#expect(staleStop.stdout == "{}\n")
#expect(waitForCondition(timeout: 2) {
#expect(waitForConditionBlocking(timeout: 2) {
commands.snapshot().count > staleStopStart
})

Expand Down