我试图了解如何正确使用TestScheduler
from RxTest 4.2
for RxSwift 4.2
。
如何正确创建 TestScheduler 并传递事件,这些事件将在所有事件执行后终止调度程序?
下面的代码在启动测试调度程序时进入无限循环。因为它保持同步循环,所以我没有机会从测试中停止调度程序
var testScheduler: TestScheduler = TestScheduler(initialClock: 0)
let stateObserver = testScheduler.createObserver(Bool.self)
subject.outputRelay.bind(to: stateObserver).disposed(by: bag)
let events = [next(1,true), next(10,false)]
let hotObservable = testScheduler.createHotObservable(events)
//direct events to the given relay
hotObservable.bind(to: subject.inputRelay).disposed(by: bag)
testScheduler.start() //infinite loop
//do not get called
XCTAssertEqual(stateObserver.events, [next(0, InterfaceState.started)])
testScheduler.stop()
我已将发布范围缩小到TestScheduler
. 订阅处置似乎有问题
func findNext() -> VirtualSchedulerItem<VirtualTime>? {
while let front = _schedulerQueue.peek() {
if front.isDisposed {
//this never gets called
_schedulerQueue.remove(front)
continue
}
return front
}
return nil
}