From 3cb61538e6008d1a93dbb9339e3df013df4ac646 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Mon, 8 Jul 2019 00:13:32 -0400 Subject: [PATCH 1/2] work-around for race condition --- src/visualizer.jl | 14 +++++++++++++- test/runtests.jl | 1 + test/wait.jl | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/wait.jl diff --git a/src/visualizer.jl b/src/visualizer.jl index 190ed0a..7232b9a 100644 --- a/src/visualizer.jl +++ b/src/visualizer.jl @@ -114,7 +114,19 @@ function send(c::CoreVisualizer, cmd::AbstractCommand) nothing end -Base.wait(c::CoreVisualizer) = WebIO.ensure_connection(c.scope.pool) +function Base.wait(c::CoreVisualizer) + pool = c.scope.pool + while true + while isready(pool.new_connections) + push!(pool.connections, take!(pool.new_connections)) + end + if !isempty(pool.connections) + break + else + sleep(0.25) + end + end +end """ vis = Visualizer() diff --git a/test/runtests.jl b/test/runtests.jl index eff7250..7469a0b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,6 +12,7 @@ using MeshIO, FileIO include("visualizer.jl") include("notebook.jl") include("scenes.jl") + include("wait.jl") end sleep(10) diff --git a/test/wait.jl b/test/wait.jl new file mode 100644 index 0000000..2e75143 --- /dev/null +++ b/test/wait.jl @@ -0,0 +1,20 @@ +# https://github.com/rdeits/MeshCat.jl/pull/99#issuecomment-509067108 + +@testset "wait" begin + @testset "with setobject" begin + vis = Visualizer() + setobject!(vis, Triad(1.0)) + open(vis) + if !haskey(ENV, "CI") + wait(vis) + end + end + + @testset "without setobject" begin + vis = Visualizer() + open(vis) + if !haskey(ENV, "CI") + wait(vis) + end + end +end From 0bfa9a5054931a0419dd7f06e974d218b587a23d Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Mon, 8 Jul 2019 21:02:19 -0400 Subject: [PATCH 2/2] fix test --- test/wait.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/wait.jl b/test/wait.jl index 2e75143..65710c7 100644 --- a/test/wait.jl +++ b/test/wait.jl @@ -4,16 +4,16 @@ @testset "with setobject" begin vis = Visualizer() setobject!(vis, Triad(1.0)) - open(vis) if !haskey(ENV, "CI") + open(vis) wait(vis) end end @testset "without setobject" begin vis = Visualizer() - open(vis) if !haskey(ENV, "CI") + open(vis) wait(vis) end end