Skip to content

Commit f45176a

Browse files
committed
Create workers only once in the thread-safety tests
This cuts the running time down from ~1m to ~10s. It shouldn't be necessary to re-create the workers for every iteration of the inner loop.
1 parent a7dabfc commit f45176a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/threads.jl

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Test
2-
using DistributedNext, Base.Threads
2+
using DistributedNext
33
using Base.Iterators: product
44

55
exeflags = ("--startup-file=no",
@@ -12,7 +12,7 @@ function call_on(f, wid, tid)
1212
t = Task(f)
1313
ccall(:jl_set_task_tid, Cvoid, (Any, Cint), t, tid - 1)
1414
schedule(t)
15-
@assert threadid(t) == tid
15+
@assert Threads.threadid(t) == tid
1616
t
1717
end
1818
end
@@ -27,12 +27,12 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
2727

2828
@testset "RemoteChannel allows put!/take! from thread other than 1" begin
2929
ws = ts = product(1:2, 1:2)
30+
31+
# We want (the default) laziness, so that we wait for `Worker.c_state`!
32+
procs_added = addprocs(2; exeflags, lazy=true)
33+
3034
@testset "from worker $w1 to $w2 via 1" for (w1, w2) in ws
3135
@testset "from thread $w1.$t1 to $w2.$t2" for (t1, t2) in ts
32-
# We want (the default) laziness, so that we wait for `Worker.c_state`!
33-
procs_added = addprocs(2; exeflags, lazy=true)
34-
@everywhere procs_added using Base.Threads
35-
3636
p1 = procs_added[w1]
3737
p2 = procs_added[w2]
3838
chan_id = first(procs_added)
@@ -57,8 +57,8 @@ isfailed(rr) = fetch_from_owner(istaskfailed, rr)
5757

5858
@test !isfailed(send)
5959
@test !isfailed(recv)
60-
61-
rmprocs(procs_added)
6260
end
6361
end
62+
63+
rmprocs(procs_added)
6464
end

0 commit comments

Comments
 (0)