Created
October 10, 2018 18:01
-
-
Save aufflick/b468fa132a506ec2d5f66c37b4e52971 to your computer and use it in GitHub Desktop.
testGCDDeterminism.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
class GCDTestTests: XCTestCase { | |
func testGCDDeterminism() { | |
// Just for sanity, confirming *everything* is happening on the serial main thread. | |
assert(Thread.isMainThread) | |
for _ in 0..<1_000 { | |
let expectations = (0..<1_000).map { self.expectation(description: "Expect \($0)") } | |
for i in 0..<1_000 { | |
DispatchQueue.main.async { | |
expectations[i].fulfill() | |
} | |
} | |
wait(for: expectations, timeout: 1, enforceOrder: true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would expect this to be deterministic, but it fairly quickly throws out of order expectation failures. Am I misunderstanding how GCD scheduling works or is this a bug?