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

Fix logging getting stuck when maxlog is specified and don't print maxlog, fixes #1902 #1911

Merged
merged 3 commits into from
Feb 15, 2022
Merged
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
6 changes: 5 additions & 1 deletion src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,13 @@ function start_relaying_logs((session, notebook)::SN, log_channel::Distributed.R
try
max_log = parse(Int, next_log["kwargs"][maybe_max_log][2] |> first)

# Don't include maxlog in the log-message, in line
# with how Julia handles it.
deleteat!(next_log["kwargs"], maybe_max_log)

# Don't show message with id more than max_log times
if max_log isa Int && n_logs >= max_log
return
continue
end
catch
end
Expand Down
67 changes: 56 additions & 11 deletions test/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,65 @@ using Pluto.WorkspaceManager: poll
🍭.connected_clients[fakeclient.id] = fakeclient

@testset "Logging respects maxlog" begin
notebook = Notebook(Cell.([
"""
for i in 1:10
@info "logging" i maxlog=2
@testset "Single log" begin
notebook = Notebook(Cell.([
"""
for i in 1:10
@info "logging" i maxlog=2
end
""",
]))

update_run!(🍭, notebook, notebook.cells)
@test notebook.cells[begin] |> noerror

@test poll(5, 1/60) do
length(notebook.cells[begin].logs) == 2
end

# Check that maxlog doesn't occur in the message
@test all(notebook.cells[begin].logs) do log
all(log["kwargs"]) do kwarg
kwarg[1] != "maxlog"
end
end

WorkspaceManager.unmake_workspace((🍭, notebook))
end

@testset "Multiple log" begin
notebook = Notebook(Cell.([
"""
for i in 1:10
@info "logging" i maxlog=2
@info "logging more" maxlog = 4
@info "even more logging"
end
""",
]))

update_run!(🍭, notebook, notebook.cells)
@test notebook.cells[begin] |> noerror

# Wait until all 16 logs are in
@test poll(5, 1/60) do
length(notebook.cells[begin].logs) == 16
end
""",
]))

update_run!(🍭, notebook, notebook.cells)
@test notebook.cells[begin] |> noerror
# Get the ids of the three logs and their counts. We are
# assuming that the logs are ordered same as in the loop.
ids = unique(getindex.(notebook.cells[begin].logs, "id"))
counts = [count(log -> log["id"] == id, notebook.cells[begin].logs) for id in ids]
@test counts == [2, 4, 10]

# Check that maxlog doesn't occur in the messages
@test all(notebook.cells[begin].logs) do log
all(log["kwargs"]) do kwarg
kwarg[1] != "maxlog"
end
end

@test poll(5, 1/60) do
length(notebook.cells[begin].logs) == 2
WorkspaceManager.unmake_workspace((🍭, notebook))
end
WorkspaceManager.unmake_workspace((🍭, notebook))
end
end