From ebf1f6ee931079e9c89a9326d56b7573d9c1a6bf Mon Sep 17 00:00:00 2001 From: Daniel Wennberg Date: Mon, 26 Aug 2024 22:42:11 -0700 Subject: [PATCH] Use local worker to support julia 1.6 and Windows --- test/Logging.jl | 48 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/test/Logging.jl b/test/Logging.jl index 3f2ba8243..294d3e8f3 100644 --- a/test/Logging.jl +++ b/test/Logging.jl @@ -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