Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jun 10, 2024
1 parent b384eb8 commit 3782e38
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,20 @@ end

@test_throws ArgumentError save(filename, Figure(), pdf_version="foo")
end

@testset "Tick Events" begin
f, a, p = scatter(rand(10));
@test events(f).tick[] == Makie.Tick()

filename = "$(tempname()).pdf"
try
save(filename, f)
tick = events(f).tick[]
@test tick.state == Makie.OneTimeRenderTick
@test tick.count == 1
@test tick.time > 1e-9
@test tick.delta_time > 1e-9
finally
rm(filename)
end
end
41 changes: 41 additions & 0 deletions GLMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,44 @@ include("unit_tests.jl")
GLMakie.closeall()
GC.gc(true) # make sure no finalizers act up!
end

@testset "Tick Events" begin
function check_tick(tick, state, count)
@test tick.state == state
@test tick.count == count
@test tick.time > 1e-9
@test tick.delta_time > 1e-9
end

f, a, p = scatter(rand(10));
@test events(f).tick[] == Makie.Tick()

filename = "$(tempname()).png"
try
Makie.save(filename, f)
tick = events(f).tick[]
check_tick(tick, Makie.OneTimeRenderTick, 1)
finally
rm(filename)
end

f, a, p = scatter(rand(10));
tick_record = Makie.Tick[]
on(t -> push!(tick_record, t), events(f).tick)
screen = GLMakie.Screen(render_on_demand = true, framerate = 30.0, pause_rendering = false, visible = false)
display(screen, f.scene)
sleep(0.15)
GLMakie.pause_renderloop!(screen)
sleep(0.1)
GLMakie.closeall()

# Why does it start with a skipped tick?
check_tick(tick_record[1], Makie.SkippedRenderTick, 1)
check_tick(tick_record[2], Makie.RegularRenderTick, 2)
i = 3
while (tick_record[i].state == Makie.SkippedRenderTick)
check_tick(tick_record[i], Makie.SkippedRenderTick, i)
i += 1
end
check_tick(tick_record[i], Makie.PausedRenderTick, i)
end
2 changes: 1 addition & 1 deletion WGLMakie/src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function Makie.colorbuffer(screen::Screen)
end
session = get_screen_session(screen; error="Not able to show scene in a browser")
screen.last_time = Makie.next_tick!(
screen.scene.events.tick, Makie.RegularRenderTick, screen.start_time, screen.last_time)
screen.scene.events.tick, Makie.OneTimeRenderTick, screen.start_time, screen.last_time)
return session2image(session, screen.scene)
end

Expand Down
44 changes: 44 additions & 0 deletions WGLMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,47 @@ end
# we used Retain for global_obs, so it should stay as long as root session is open
@test keys(js_objects) == Set([WGLMakie.TEXTURE_ATLAS.id])
end

@testset "Tick Events" begin
function check_tick(tick, state, count)
@test tick.state == state
@test tick.count == count
@test tick.time > 1e-9
@test tick.delta_time > 1e-9
end

f, a, p = scatter(rand(10));
@test events(f).tick[] == Makie.Tick()
tick_record = Makie.Tick[]
on(t -> push!(tick_record, t), events(f).tick)

filename = "$(tempname()).png"
try
save(filename, f)
# WGLMakie produces a running renderloop when calling colorbuffer so
# we have multiple ticks to deal with
idx = findfirst(tick -> tick.state == Makie.OneTimeRenderTick, tick_record)
@test idx !== nothing
check_tick(tick_record[idx], Makie.OneTimeRenderTick, idx)
finally
rm(filename)
end

# This produces a lot of pre-render ticks claiming to be normal render ticks
f, a, p = scatter(rand(10));
tick_record = Makie.Tick[]
on(t -> push!(tick_record, t), events(f).tick)
screen = display(f)
sleep(0.1)
close(screen)

# May have preceeding ticks from previous renderloop
start = 1
while tick_record[start].count > 1
start += 1
end

for i in start:length(tick_record)
check_tick(tick_record[i], Makie.RegularRenderTick, i-start+1)
end
end

0 comments on commit 3782e38

Please sign in to comment.