You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that XCTestCase.expectation(description: "…") calls through to XCTestCase.addExpectation(…) which asserts that it is being called from the main thread. See
precondition(Thread.isMainThread,"\(#function) must be called on the main thread")
for the implementation of this.
When running in an async test case, the test case is not always run on the main thread, so the test fails and crashes the running suite due to this assertion.
A simple test case is to call the following code within an async test, something like:
Environment
I was using the
swiftlang/swift:nightly-5.5-focal
Docker tag on the 1st December, 2021.Additional Detail from JIRA
md5: 219c66c7d78a9418491933d5732beff1
Issue Description:
It appears that XCTestCase.expectation(description: "…") calls through to XCTestCase.addExpectation(…) which asserts that it is being called from the main thread. See
swift-corelibs-xctest/Sources/XCTest/Public/XCTestCase.swift
Line 63 in 1b0e65c
When running in an async test case, the test case is not always run on the main thread, so the test fails and crashes the running suite due to this assertion.
A simple test case is to call the following code within an async test, something like:
And then run it on Linux using any recent Swift 5.5 snapshot.
The same code runs fine under macOS under Xcode 13.2 beta 2, so this appears to be a difference between Swift's implementation of XCTest and Xcode's.
The text was updated successfully, but these errors were encountered: