Skip to content

Commit ab84b2f

Browse files
authored
Allow multiple async polling expectations (#1189)
This partially solves the issue of swift testing's concurrent test runner tripping the 'nested polling expectation' error. Solving this for synchronous polling expectations will be much more involved. As synchronous polling expectations actually run all the test code on the main runloop.
1 parent 23903e1 commit ab84b2f

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Sources/Nimble/Utils/AsyncAwait.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal enum AsyncPollResult<T> {
6060
internal actor AsyncPromise<T> {
6161
private let storage = Storage()
6262

63-
private final class Storage {
63+
private final class Storage: @unchecked Sendable {
6464
private var continuations: [UnsafeContinuation<T, Never>] = []
6565
private var value: T?
6666
// Yes, this is not the fastest lock, but it's platform independent,
@@ -142,7 +142,8 @@ private func timeout<T>(timeoutQueue: DispatchQueue, timeoutInterval: NimbleTime
142142
let semTimedOutOrBlocked = DispatchSemaphore(value: 0)
143143
semTimedOutOrBlocked.signal()
144144

145-
DispatchQueue.main.async {
145+
let timeoutQueue = DispatchQueue(label: "org.quick.nimble.timeoutQueue", qos: .userInteractive)
146+
timeoutQueue.async {
146147
if semTimedOutOrBlocked.wait(timeout: .now()) == .success {
147148
timedOutSem.signal()
148149
semTimedOutOrBlocked.signal()
@@ -202,14 +203,6 @@ private func runPoller(
202203
sourceLocation: SourceLocation,
203204
expression: @escaping () async throws -> PollStatus
204205
) async -> AsyncPollResult<Bool> {
205-
awaiter.waitLock.acquireWaitingLock(
206-
fnName,
207-
sourceLocation: sourceLocation
208-
)
209-
210-
defer {
211-
awaiter.waitLock.releaseWaitingLock()
212-
}
213206
let timeoutQueue = awaiter.timeoutQueue
214207
return await withTaskGroup(of: AsyncPollResult<Bool>.self) { taskGroup in
215208
taskGroup.addTask {

0 commit comments

Comments
 (0)