Skip to content

Commit

Permalink
Add tests for thread safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Aug 7, 2020
1 parent b4125ba commit 54b99fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ include("convert.jl")
include("macros.jl")
include("packages.jl")
include("help.jl")
include("sync.jl")
# include("testmanual.jl") # leave this out until doctestfilters can be used here
36 changes: 36 additions & 0 deletions test/sync.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function run_timed(script :: String, timeout :: Int)
cmd = Cmd(Base.julia_cmd();
env = merge(ENV, Dict("JULIA_NUM_THREADS" => "2")))
push!(cmd.exec, "-e", script)
process = open(cmd)
task = @async begin
wait(process)
end
for t in 1:(timeout*10)
sleep(0.1)
if task.state == :done
return process.exitcode == 0
end
end
kill(process, 9)
return false
end

@testset "sync" begin
@test run_timed("""
using GAP
Threads.@threads for i = 1:20000
GAP.Globals.SymmetricGroup(7)
end
""", 10)
@test run_timed("""
using GAP
function test()
perm = @gap "()"
Threads.@threads for i = 1:2000
perm *= GAP.evalstr("(\$(i), \$(i+1))")
end
end
test()
""", 10)
end

0 comments on commit 54b99fc

Please sign in to comment.