Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

booktest: add hangcheck timer to print current file+line, and later backtrace #4504

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions test/book/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,25 @@ isdefined(Main, :FakeTerminals) || include(joinpath(pkgdir(REPL),"test","FakeTer
close(mockrepl.output)
end

function run_repl_string(mockrepl::MockREPLHelper, s::AbstractString; jlcon_mode=true)
function run_repl_string(mockrepl::MockREPLHelper, s::AbstractString; jlcon_mode=true, filename=nothing)
(hangdelay, hanginterval) = (10, 5)
hangcount = hangdelay
hangwarn = Timer(60*hangdelay; interval=60*hanginterval) do t
println(stderr, " Hangcheck triggered:")
filename === nothing || println(stderr, " +$(hangcount)min Current file: ", filename)
# the argument s contains the full example file as a string
# to get the currently running line we fetch this from the repl history
println(stderr, " +$(hangcount)min Current line: ", Base.active_repl.mistate.current_mode.hist.history[end])
# print backtrace if we are stuck for more than two times the initial limit
if hangcount > hangdelay*2
sig = Sys.islinux() ? "-USR1" : "-INFO"
# with short delay so that we are out of the hangcheck task
run(`sh -c "sleep 5 && kill $sig $(getpid())"`)
end
hangcount += hanginterval
end
input_string = s
@debug "running repl string:\n$s"
if jlcon_mode
input_string = "\e[200~$s\e[201~"
end
Expand Down Expand Up @@ -195,9 +212,11 @@ isdefined(Main, :FakeTerminals) || include(joinpath(pkgdir(REPL),"test","FakeTer
end
REPL.activate(Main)
output = sanitize_output(result)
close(hangwarn)
if !jlcon_mode && haderror
error("ERROR in jl-mode:\n", output)
end
@debug "repl output:\n$output"
return output
end

Expand Down Expand Up @@ -265,10 +284,10 @@ isdefined(Main, :FakeTerminals) || include(joinpath(pkgdir(REPL),"test","FakeTer
@debug "possibly wrong file type: $full_file"
end
if full_file in skipped
@test run_repl_string(mockrepl, content) isa AbstractString skip=true
@test run_repl_string(mockrepl, content; filename=full_file) isa AbstractString skip=true
elseif filetype == :jlcon
content = sanitize_input(content)
computed = run_repl_string(mockrepl, content)
computed = run_repl_string(mockrepl, content; filename=full_file)
res = @test normalize_repl_output(content) == computed broken=(full_file in broken)
if res isa Test.Fail
println(deepdiff(normalize_repl_output(content),computed))
Expand All @@ -277,9 +296,9 @@ isdefined(Main, :FakeTerminals) || include(joinpath(pkgdir(REPL),"test","FakeTer
if occursin("# output\n", content)
(code, res) = split(content, "# output\n"; limit=2)
# TODO do we want to compare with `res` ?
@test run_repl_string(mockrepl, code; jlcon_mode=false) isa AbstractString broken=(full_file in broken)
@test run_repl_string(mockrepl, code; jlcon_mode=false, filename=full_file) isa AbstractString broken=(full_file in broken)
else
@test run_repl_string(mockrepl, content; jlcon_mode=false) isa AbstractString broken=(full_file in broken)
@test run_repl_string(mockrepl, content; jlcon_mode=false, filename=full_file) isa AbstractString broken=(full_file in broken)
end
else
@warn "unknown file type: $full_file"
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
# to make sure we seed the main process we run this again
Oscar.randseed!(seed)

if VERSION >= v"1.8.0"
if VERSION >= v"1.8.0" && get(ENV, "CI", "") == "true"
# Enable GC logging to help track down certain GC related issues.
# Note that several test files need to temporarily disable and then
# re-enable this. If we need to disable this globally, those files
Expand Down
Loading