Skip to content

Commit e4fe20e

Browse files
committed
add error test
1 parent 78006a1 commit e4fe20e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test/logging.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,26 @@ end
5555
end
5656
end
5757
end
58+
59+
@testset "Logging errors are caught and don't crash" begin
60+
problem = LogDummyProblem()
61+
algorithm = LogDummyAlgorithm(StopAfterIteration(3))
62+
63+
# Action that throws on the second iteration
64+
flaky_logger = CallbackAction() do problem, algorithm, state
65+
if state.iteration == 2
66+
error("Boom")
67+
else
68+
@info "Iter $(state.iteration)"
69+
end
70+
end
71+
72+
# We expect:
73+
# - an error log emitted by the logging infrastructure on iter 2
74+
# - info logs for iterations 1 and 3
75+
@test_logs (:info, "Iter 1") (:error, "Error during the handling of a logging action") (:info, "Iter 3") begin
76+
with_algorithmlogger(:PostStep => flaky_logger) do
77+
solve(problem, algorithm)
78+
end
79+
end
80+
end

0 commit comments

Comments
 (0)