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
RxTest TestScheduler didn't work if the observable stream include async await usage (wrapped with AsyncThrowingStream)
In some case it will throw Fatal error: Executing on background thread. Please use MainScheduler.instance.schedule to schedule work on main thread
No matter using @MainActor or not, it won't get any value when checking the output from TestableObserver
Expected outcome:
Test case run successfully
What actually happens:
Test case got empty event
Self contained code example that reproduces the issue:
classMyClass{@MainActorfunc doubleValue(input:Observable<Int>)->Observable<Int>{// Remove @MainActo will trigger errorreturnAsyncThrowingStream{letval=tryawait input.first().value ??0return val *2// Use dummy value for testing here, however sometime may consume another async function in here}.asObservable()}}@MainActorfinalclassRxSwiftTestingTests:XCTestCase{vardisposeBag=DisposeBag()func testMyClass()throws{letscheduler=TestScheduler(initialClock:0)letinput= scheduler.createColdObservable([.next(0,1),.completed(0)]).asObservable()letc=MyClass()letobserver= scheduler.createObserver(Int.self)
c.doubleValue(input: input).bind(to: observer).disposed(by: disposeBag)
scheduler.start()XCTAssertEqual(observer.events,[.next(0,2),.completed(0)])}}
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
RxSwift 6.6.0
Platform/Environment
iOS
macOS
tvOS
watchOS
playgrounds
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
easy, 100% repro
sometimes, 10%-100%
hard, 2% - 10%
extremely hard, %0 - 2%
Xcode version:
14.3.1 (14E300c)
The text was updated successfully, but these errors were encountered:
This is expected behavior. A TestScheduler is not asynchronous. If you need to test asynchronous behavior, you will have to follow the instructions in Asynchronous Tests and Expectations instead of using TestScheduler.
This is the reason (or at least part of the reason) the async producer operators (eg timer) all accept a Scheduler as a parameter, so you can substitute a TestScheduler and turn them synchronous.
Short description of the issue:
RxTest TestScheduler didn't work if the observable stream include async await usage (wrapped with AsyncThrowingStream)
In some case it will throw
Fatal error: Executing on background thread. Please use MainScheduler.instance.schedule to schedule work on main thread
No matter using
@MainActor
or not, it won't get any value when checking the output from TestableObserverExpected outcome:
Test case run successfully
What actually happens:
Test case got empty event
Self contained code example that reproduces the issue:
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
RxSwift 6.6.0
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
The text was updated successfully, but these errors were encountered: