-
Describe the bug To Reproduce // And/or enter code that reproduces the behavior here.
final class CombineSchedulersPOCTests: XCTestCase {
func test() async {
let startTime = CFAbsoluteTimeGetCurrent()
var testSubject = PassthroughSubject<Bool, Error>()
let test = DispatchQueue.test
print("##### INITIALIZED #####")
print(CFAbsoluteTimeGetCurrent() - startTime)
testSubject.send(true)
print("##### sent true #####")
print(CFAbsoluteTimeGetCurrent() - startTime)
testSubject.send(completion: .finished)
print("##### sent finished #####")
print(CFAbsoluteTimeGetCurrent() - startTime)
await test.advance()
print("##### advance #####")
print(CFAbsoluteTimeGetCurrent() - startTime)
}
} Expected behavior Environment
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @edhirama, this is just due to the fact that async/await is still not very testable in Swift, and so we are forced to resort to tricks like this If you want to invoke the non-async version of func test() async {
let startTime = CFAbsoluteTimeGetCurrent()
let test = DispatchQueue.test
_ = { test.advance() }()
print("##### advance #####")
print(CFAbsoluteTimeGetCurrent() - startTime)
} Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there! |
Beta Was this translation helpful? Give feedback.
Hi @edhirama, this is just due to the fact that async/await is still not very testable in Swift, and so we are forced to resort to tricks like this
megaYield
to make sure work has time to execute:combine-schedulers/Sources/CombineSchedulers/TestScheduler.swift
Line 136 in 5928286
If you want to invoke the non-async version of
advance
you can always wrap it in a synchronous closure and invoke it:Since this isn't an issue with the library I am goi…