swiftlang / swift-corelibs-xctest

The XCTest Project, A Swift core library for providing unit test support
swift.org
Apache License 2.0
1.15k stars 267 forks source link

await fulfillment(of: [exp]) does take more time than needed. #469

Closed agiokas closed 1 year ago

agiokas commented 1 year ago

A quite strange behaviour when using the await fulfillment(of: [exp])

final class XCtestPerformanceTests: XCTestCase {
    func testWaitForValue_Exp() async {
        let exp = expectation(description: "My Expectation")
        Task {
            exp.fulfill()
        }
        await fulfillment(of: [exp])
    }
}

when using a timeout bigger than 0.1 sec many tests take around 0.1 sec to complete.

 Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 1 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.001 seconds).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 2 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.106 seconds).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 3 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.105 seconds).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 4 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.001 seconds).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 5 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.001 seconds).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' started (Iteration 6 of 100).
Test Case '-[XCtestPerformanceTests.XCtestPerformanceTests testWaitForValue_Exp]' passed (0.104 seconds).

Reproducible in Xcode: 15.0

Issue was not reproducible in Xcode 14.x

grynspan commented 1 year ago

This repository tracks the open-source XCTest implementation used on Linux. For issues with the copy of XCTest that ships with Xcode on macOS, please file feedback using Apple's Feedback Assistant.