Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
test reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jan 19, 2022
1 parent 757327f commit 3c908a8
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 78 deletions.
105 changes: 105 additions & 0 deletions test/eventloop.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@testset "eventloop" begin
# make sure all shown widgets have been destroyed, otherwise the eventloop
# won't stop automatically
@test length(Gtk.shown_widgets) == 0

@testset "control" begin
before = Gtk.auto_idle[]

@testset "basics" begin
Gtk.auto_idle[] = true
Gtk.enable_eventloop(false)
@test !Gtk.is_eventloop_running()
Gtk.enable_eventloop(true)
@test Gtk.is_eventloop_running()
Gtk.enable_eventloop(false)
@test !Gtk.is_eventloop_running()
end

@testset "pause_eventloop" begin

@testset "pauses then restarts" begin
Gtk.enable_eventloop(true)
@test Gtk.is_eventloop_running()
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()
end

@testset "doesn't restart a stopping eventloop" begin
Gtk.enable_eventloop(false)
c = GtkCanvas()
win = GtkWindow(c)
showall(win)
sleep(1)
@test Gtk.is_eventloop_running()
destroy(win)
# the eventloop is likely still stopping here
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
end
@test !Gtk.is_eventloop_running()
end

@testset "observes auto_idle = false" begin
Gtk.auto_idle[] = false
Gtk.enable_eventloop(true)
Gtk.pause_eventloop() do
@test Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()
end

@testset "observes force = true" begin
Gtk.auto_idle[] = false
Gtk.enable_eventloop(true)
Gtk.pause_eventloop(force = true) do
@test !Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()
end

# Note: Test disabled because this isn't true. The event loop takes some time to stop.
# TODO: Figure out how to wait in the handle_auto_idle callbacks

# @testset "eventloop is stopped immediately after a destroy(win) completes" begin
# c = GtkCanvas()
# win = GtkWindow(c)
# showall(win)
# @test Gtk.is_eventloop_running()
# destroy(win)
# @test !Gtk.is_eventloop_running()
# end
end

Gtk.auto_idle[] = before
end

@testset "Multithreading" begin
@testset "no blocking when eventloop is paused" begin
Gtk.auto_idle[] = true
Threads.nthreads() < 1 && @warn "Threads.nthreads() == 1. Multithread blocking tests are not effective"

function multifoo()
Threads.@threads for _ in 1:Threads.nthreads()
sleep(0.1)
end
end

Gtk.enable_eventloop(false)
win = Gtk.Window("Multithread test", 400, 300)
showall(win)
@test Gtk.is_eventloop_running()
for i in 1:10
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
t = @elapsed multifoo() # should take slightly more than 0.1 seconds
@test t < 4.5 # given the Glib uv_prepare timeout is 5000 ms
end
end
@test Gtk.is_eventloop_running()
destroy(win)
end
end
end
78 changes: 0 additions & 78 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,82 +38,4 @@ destroy(win)

@test isa(Gtk.GdkEventKey(), Gtk.GdkEventKey)

# make sure all shown widgets have been destroyed, otherwise the eventloop
# won't stop automatically
@test length(Gtk.shown_widgets) == 0

@testset "Eventloop control" begin
before = Gtk.auto_idle[]

Gtk.enable_eventloop(true)
@test Gtk.is_eventloop_running()

Gtk.auto_idle[] = true
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()

Gtk.auto_idle[] = false
Gtk.pause_eventloop() do
@test Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()

Gtk.pause_eventloop(force = true) do
@test !Gtk.is_eventloop_running()
end
@test Gtk.is_eventloop_running()
Gtk.enable_eventloop(false)
@test !Gtk.is_eventloop_running()

@testset "pause_eventloop: multithreaded code doesn't block" begin
Gtk.auto_idle[] = true
Threads.nthreads() < 1 && @warn "Threads.nthreads() == 1. Multithread blocking tests are not effective"

function multifoo()
Threads.@threads for _ in 1:Threads.nthreads()
sleep(0.1)
end
end

@test !Gtk.is_eventloop_running()
win = Gtk.Window("Multithread test", 400, 300)
showall(win)
@test Gtk.is_eventloop_running()
for i in 1:10
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
t = @elapsed multifoo() # should take slightly more than 0.1 seconds
@test t < 4.5 # given the Glib uv_prepare timeout is 5000 ms
end
end
@test Gtk.is_eventloop_running()
destroy(win)
end

@testset "eventloop is stopped immediately after a destroy(win) completes" begin
c = GtkCanvas()
win = GtkWindow(c)
showall(win)
@test Gtk.is_eventloop_running()
destroy(win)
@test !Gtk.is_eventloop_running()
end

@testset "pause_eventloop: doesn't restart a stopping eventloop" begin
c = GtkCanvas()
win = GtkWindow(c)
showall(win)
@test Gtk.is_eventloop_running()
destroy(win)
Gtk.pause_eventloop() do
@test !Gtk.is_eventloop_running()
end
@test !Gtk.is_eventloop_running()
end

Gtk.auto_idle[] = before
end

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ include("gui.jl")
include("list.jl")
include("misc.jl")
include("text.jl")
include("eventloop.jl")

end

0 comments on commit 3c908a8

Please sign in to comment.