Timeout Issues with Async Polling in Xcode Cloud

Hi,

Our team uses Xcode Cloud to run unit tests, and since around November, we’ve been frequently experiencing timeouts with the following type of process:


@Test func hogeTest() async {
    // do something
    hoge.do()

    // wait until done
    await wait(condition: { hoge.isDone })

    // test result
    #expect(hoge.isSucceeded)
}

private func wait(condition: () async -> Bool, timeout: TimeInterval = 0.5, pollingInterval: TimeInterval = 0.01) async throws {
    let deadline = Date().addingTimeInterval(timeout)
    while Date() < deadline {
        if await condition() { return }
        try await Task.sleep(nanoseconds: UInt64(round(pollingInterval * TimeInterval(NSEC_PER_SEC))))
    }
    Issue.record("timeout")
}

Although sleep is supposed to wait for only a few milliseconds, there are cases where it takes more than 10 seconds, leading to a timeout.

What could be causing this instability in the sleep duration? Additionally, if there are other recommended ways to implement polling and waiting in Swift Testing, I would appreciate it if you could share them.

A feedback report (FB15899163) has already been submitted.

Best regards,

Thank you for filing your Feedback report. We need more information in order to investigate your issue. Please attach the logs from a build where the timeout occurred to your FB15899163 report.

Timeout Issues with Async Polling in Xcode Cloud
 
 
Q