Skip to content

Commit 6bf3c7c

Browse files
committed
tests for raising errors
1 parent b304036 commit 6bf3c7c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/concurrent/dataflow.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def dataflow_with(executor, *inputs, &block)
9090
module_function :dataflow_with
9191

9292
def dataflow!(*inputs, &block)
93-
dataflow_with(Concurrent.configuration.global_task_pool, *inputs, &block)
93+
dataflow_with!(Concurrent.configuration.global_task_pool, *inputs, &block)
9494
end
9595
module_function :dataflow!
9696

spec/concurrent/dataflow_spec.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,40 @@ def fib_with_dot(n)
221221
expect(expected.value).to eq 377
222222
end
223223

224-
it 'can be called as Concurrent::dataflow and Concurrent::dataflow_with' do
224+
it 'can be called as Concurrent::dataflow! and Concurrent::dataflow_with' do
225225

226226
def fib_with_colons(n)
227227
if n < 2
228-
Concurrent::dataflow { n }
228+
Concurrent::dataflow! { n }
229229
else
230230
n1 = fib_with_colons(n - 1)
231231
n2 = fib_with_colons(n - 2)
232-
Concurrent::dataflow_with(root_executor, n1, n2) { n1.value + n2.value }
232+
Concurrent::dataflow_with!(root_executor, n1, n2) { n1.value + n2.value }
233233
end
234234
end
235235

236236
expected = fib_with_colons(14)
237237
sleep(0.1)
238238
expect(expected.value).to eq 377
239239
end
240+
241+
it 'dataflow! raises exceptions from dependencies, and dataflow doesn\'t' do
242+
243+
def raiser
244+
Concurrent::dataflow(){raise}
245+
end
246+
247+
d1 = raiser
248+
d2 = raiser
249+
f = Concurrent::dataflow!(d1, d2){|d1v, d2v| [d1v,d2v]}
250+
expect{f.value!}.to raise_error
251+
252+
d1 = raiser
253+
d2 = raiser
254+
f = Concurrent::dataflow(d1, d2){|d1v, d2v| [d1v,d2v]}
255+
expect{f.value!}.to_not raise_error
256+
end
257+
240258
end
241259
end
242260
end

0 commit comments

Comments
 (0)