Skip to content

Commit 61bb51a

Browse files
tweak & expand tests
1 parent b813bf6 commit 61bb51a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

test/threads_exec.jl

+17-10
Original file line numberDiff line numberDiff line change
@@ -722,15 +722,16 @@ let a = zeros(nthreads())
722722
end
723723

724724
# static schedule
725-
function _atthreads_static_schedule()
726-
ids = zeros(Int, nthreads())
727-
Threads.@threads :static for i = 1:nthreads()
725+
function _atthreads_static_schedule(n)
726+
ids = zeros(Int, n)
727+
Threads.@threads :static for i = 1:n
728728
ids[i] = Threads.threadid()
729729
end
730730
return ids
731731
end
732-
@test _atthreads_static_schedule() == [1:nthreads();]
733-
@test_throws TaskFailedException @threads for i = 1:1; _atthreads_static_schedule(); end
732+
@test _atthreads_static_schedule(nthreads()) == [1:nthreads();]
733+
@test _atthreads_static_schedule(1) == [1;]
734+
@test_throws TaskFailedException @threads for i = 1:1; _atthreads_static_schedule(nthreads()); end
734735

735736
# dynamic schedule
736737
function _atthreads_dynamic_schedule(n)
@@ -757,8 +758,7 @@ function _atthreads_dynamic_dynamic_schedule()
757758
end
758759
return inc[]
759760
end
760-
inc = _atthreads_dynamic_dynamic_schedule()
761-
@test inc == nthreads() * nthreads()
761+
@test _atthreads_dynamic_dynamic_schedule() == nthreads() * nthreads()
762762

763763
function _atthreads_static_dynamic_schedule()
764764
ids = zeros(Int, nthreads())
@@ -771,9 +771,16 @@ function _atthreads_static_dynamic_schedule()
771771
end
772772
return ids, inc[]
773773
end
774-
ids, inc = _atthreads_static_dynamic_schedule()
775-
@test ids == [1:nthreads();]
776-
@test inc == nthreads() * nthreads()
774+
@test _atthreads_static_dynamic_schedule() == ([1:nthreads();], nthreads() * nthreads())
775+
776+
# errors inside @threads :dynamic
777+
function _atthreads_dynamic_with_error(a)
778+
Threads.@threads :dynamic for i in eachindex(a)
779+
error("failed")
780+
end
781+
a
782+
end
783+
@test_throws TaskFailedException _atthreads_dynamic_with_error(zeros(nthreads()))
777784

778785
try
779786
@macroexpand @threads(for i = 1:10, j = 1:10; end)

0 commit comments

Comments
 (0)