Skip to content

Commit 201ad69

Browse files
committed
use channel to make test more robust
1 parent 8f341a3 commit 201ad69

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/sample.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,14 +681,16 @@
681681

682682
@testset "chain_number keyword argument" begin
683683
@testset for m in [MCMCSerial(), MCMCThreads(), MCMCDistributed()]
684-
# check that the `chain_number` keyword argument is passed to the callback
685-
chain_numbers = Int[]
686-
function callback(args...; kwargs...)
687-
@test haskey(kwargs, :chain_number)
688-
return push!(chain_numbers, kwargs[:chain_number])
689-
end
690684
niters = 10
691-
chain = sample(MyModel(), MySampler(), m, niters, 4; callback=callback)
685+
channel = Channel{Int}() do chn
686+
# check that the `chain_number` keyword argument is passed to the callback
687+
function callback(args...; kwargs...)
688+
@test haskey(kwargs, :chain_number)
689+
return put!(chn, kwargs[:chain_number])
690+
end
691+
chain = sample(MyModel(), MySampler(), m, niters, 4; callback=callback)
692+
end
693+
chain_numbers = collect(channel)
692694
# if the test fails, the output is too long to show, so print it manually to see
693695
# what's going on
694696
if sort(chain_numbers) != repeat(1:4; inner=niters)

0 commit comments

Comments
 (0)