Skip to content

Commit

Permalink
Use local worker to support julia 1.6 and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwe committed Aug 27, 2024
1 parent 050860a commit ebf1f6e
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions test/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,49 +211,17 @@ using Pluto.WorkspaceManager: poll
cleanup(🍭, notebook)

@testset "Logging error fallback" begin
# This testset needs a separate server session to capture the process stderr (which
# is different from the notebook stderr)
# This testset needs to use a local worker to capture the worker stderr (which is
# different from the notebook stderr)
🍍 = ServerSession()
🍍.options.evaluation.workspace_use_distributed = false

msg = if true
# Alternative 1: use a remote worker and capture stderr using redirect_stderr.
# The reason we cannot use the same session as above is that a Malt.Worker's
# stderr is bound to the local stderr when the worker is instantiated, which
# happens at the first call to update_run! with a given session and notebook.
# Since update_run! has been called several times above, the existing worker's
# stderr is already bound to the local TTY, and redirect_stderr won't change
# that. We need a new session such that we can instantiate a new worker within
# the redirect_stderr block. (An alternative would be to move this testset to
# the top of the file such that it gets the first call to update_run!, but it
# seems like a bad idea to have tests that may pass or fail depending on the
# order of the testsets.)
#
# This argument is specific to Malt. Distributed relays stderr differently.
🍍.options.evaluation.workspace_use_distributed = true

pipe = Pipe()
redirect_stderr(pipe) do
update_run!(🍍, notebook, notebook.cells[27:29])
end
t = Threads.@spawn read(pipe, String)
close(pipe)
fetch(t)
else
# Alternative 2: use a local worker and capture stderr using
# PlutoRunner.redirect_original_stderr. This avoids the complications due to
# stderr relaying between processes and Malt implementation details, but
# requires using a bespoke redirection function from PlutoRunner rather than
# Base.redirect_stderr.
🍍.options.evaluation.workspace_use_distributed = false

io = IOBuffer()
PlutoRunner.redirect_original_stderr(io) do
update_run!(🍍, notebook, notebook.cells[27:29])
end
msg_ = String(take!(io))
close(io)
msg_
io = IOBuffer()
PlutoRunner.redirect_original_stderr(io) do
update_run!(🍍, notebook, notebook.cells[27:29])
end
msg = String(take!(io))
close(io)

@test notebook.cells[27] |> noerror
@test notebook.cells[28] |> noerror
Expand Down

0 comments on commit ebf1f6e

Please sign in to comment.