Skip to content

Commit

Permalink
Failing tests for recursive behavior with buffer()
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jul 5, 2015
1 parent 79909dd commit 04d2c5b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ReactiveCocoaTests/Swift/SignalProducerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,58 @@ class SignalProducerSpec: QuickSpec {
expect(value).to(equal(123))
expect(completed).to(beTruthy())
}

it("should not deadlock when started while sending") {
let (producer, sink) = SignalProducer<Int, NoError>.buffer()

sendNext(sink, 1)
sendNext(sink, 2)
sendNext(sink, 3)

var values: [Int] = []
producer.start(completed: {
values = []

producer.start(next: { value in
values.append(value)
})
})

sendCompleted(sink)
expect(values).to(equal([ 1, 2, 3 ]))
}

it("should buffer values before sending recursively to new observers") {
let (producer, sink) = SignalProducer<Int, NoError>.buffer()

var values: [Int] = []
var lastBufferedValues: [Int] = []

producer.start(next: { newValue in
values.append(newValue)

var bufferedValues: [Int] = []

producer.start(next: { bufferedValue in
bufferedValues.append(bufferedValue)
})

expect(bufferedValues).to(equal(values))
lastBufferedValues = bufferedValues
})

sendNext(sink, 1)
expect(values).to(equal([ 1 ]))
expect(lastBufferedValues).to(equal(values))

sendNext(sink, 2)
expect(values).to(equal([ 1, 2 ]))
expect(lastBufferedValues).to(equal(values))

sendNext(sink, 3)
expect(values).to(equal([ 1, 2, 3 ]))
expect(lastBufferedValues).to(equal(values))
}
}

describe("SignalProducer.try") {
Expand Down

0 comments on commit 04d2c5b

Please sign in to comment.