Skip to content

Commit 5be24a3

Browse files
andersioNachoSoto
authored andcommitted
Add a producer interruption test case.
1 parent c56fa13 commit 5be24a3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/ReactiveSwiftTests/SignalProducerSpec.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,30 @@ class SignalProducerSpec: QuickSpec {
599599
let producer = SignalProducer<Never, NoError>.empty
600600
expect(producer.startWithSignal { _, _ in "Hello" }) == "Hello"
601601
}
602+
603+
it("should dispose of the upstream when the downstream producer terminates") {
604+
var iterationCount = 0
605+
606+
let loop = SignalProducer<Int, NoError> { observer, lifetime in
607+
for i in 0 ..< 100 where !lifetime.hasEnded {
608+
observer.send(value: i)
609+
iterationCount += 1
610+
}
611+
observer.sendCompleted()
612+
}
613+
614+
var results: [Int] = []
615+
616+
waitUntil { done in
617+
loop
618+
.lift { $0.take(first: 5) }
619+
.on(disposed: done)
620+
.startWithValues { results.append($0) }
621+
}
622+
623+
expect(iterationCount) == 5
624+
expect(results) == [0, 1, 2, 3, 4]
625+
}
602626
}
603627

604628
describe("start") {

0 commit comments

Comments
 (0)