Skip to content

Ensure tests work in deployments that host as swift 5.7 #285

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2023
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
5 changes: 3 additions & 2 deletions Tests/AsyncAlgorithmsTests/Performance/TestThroughput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ final class TestThroughput: XCTestCase {
zip($0, $1, $2)
}
}
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
func test_debounce() async {
if #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) {
await measureSequenceThroughput(source: (1...).async) {
$0.debounce(for: .zero, clock: ContinuousClock())
$0.debounce(for: .zero, clock: ContinuousClock())
}
}
}
}
#endif
44 changes: 44 additions & 0 deletions Tests/AsyncAlgorithmsTests/Support/Asserts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,47 @@ internal func XCTAssertThrowsError<T>(
verify(error)
}
}

class WaiterDelegate: NSObject, XCTWaiterDelegate {
let state: ManagedCriticalState<UnsafeContinuation<Void, Never>?> = ManagedCriticalState(nil)

init(_ continuation: UnsafeContinuation<Void, Never>) {
state.withCriticalRegion { $0 = continuation }
}

func waiter(_ waiter: XCTWaiter, didFulfillInvertedExpectation expectation: XCTestExpectation) {
resume()
}

func waiter(_ waiter: XCTWaiter, didTimeoutWithUnfulfilledExpectations unfulfilledExpectations: [XCTestExpectation]) {
resume()
}

func waiter(_ waiter: XCTWaiter, fulfillmentDidViolateOrderingConstraintsFor expectation: XCTestExpectation, requiredExpectation: XCTestExpectation) {
resume()
}

func nestedWaiter(_ waiter: XCTWaiter, wasInterruptedByTimedOutWaiter outerWaiter: XCTWaiter) {

}

func resume() {
let continuation = state.withCriticalRegion { continuation in
defer { continuation = nil }
return continuation
}
continuation?.resume()
}
}

extension XCTestCase {
@_disfavoredOverload
func fulfillment(of expectations: [XCTestExpectation], timeout: TimeInterval, enforceOrder: Bool = false, file: StaticString = #file, line: Int = #line) async {
return await withUnsafeContinuation { continuation in
let delegate = WaiterDelegate(continuation)
let waiter = XCTWaiter(delegate: delegate)
waiter.wait(for: expectations, timeout: timeout, enforceOrder: enforceOrder)
delegate.resume()
}
}
}