Skip to content

Conversation

@hubertp
Copy link
Collaborator

@hubertp hubertp commented Aug 1, 2025

Pull Request Description

This change simplifies the existing MemoryAppender in order to accommodate for setting up Loggers in both, JUnit and ScalaTest. This change adds support for reporting logs on failures via JUnit's Rules.
Made sure that (in most cases) we use JulHandler as engine's log handler so that logs are appropriately forwarded to slf4j for processing.

The functionality stays as before. The only difference is that we now have logs being reported when a test fails.
Closes #13308.

Important Notes

A ReportLogsOnFailure has already been used in LS but not in runtime-integration-tests. It also didn't work well with logs in engine.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

This change simplifies the existing `MemoryAppender` in order to
accomodate for setting up Loggers in both, JUnit and ScalaTest.

A `ReportLogsOnFailure` has already been used in LS but not in
`runtime-integration-tests`. It also didn't work for logs in engine.
Junit implements "logs on failure" via rules.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Aug 1, 2025
hubertp added 4 commits August 4, 2025 17:22
More tests use the "report logs on failure only" feature.
`trace` level seems more useful now that logs are printed only when
necessary.
Rather than following all `newBuilder` by `withLogHandler` ones, making
the builder use `JulHandler` by default.
This change required changes to `ExecCompilerTest` and
`HelloWorldCacheTest` to make use of log messages rather than stdout.
@hubertp hubertp force-pushed the wip/hubert/13308-logs-on-failure branch from c636b81 to 25a1f80 Compare August 4, 2025 21:37
"-Dtck.inlineVerifierInstrument=false",
"-Dpolyglot.engine.AllowExperimentalOptions=true"
),
Test / javacOptions += "-implicit:none",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR but reduces warnings noise.

@hubertp hubertp marked this pull request as ready for review August 6, 2025 09:02
Copy link
Contributor

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having another @Rule definition seems like a duplicate on many tests that already have @Rule ContextUtils. Can't the new logging behavior be the default for ContextUtils?

@hubertp
Copy link
Collaborator Author

hubertp commented Aug 8, 2025

I will have another run at all those changed tests and see if I can somehow eliminate the few exceptions that needed manual settings.

@hubertp hubertp added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Aug 11, 2025
Reduced redundant `logHandler` setup in various places.
@hubertp hubertp requested a review from Akirathan August 11, 2025 14:23
Copy link
Contributor

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. Ideally, this behavior should somehow be enforced for all the tests. In a few months, when we all start forgetting to put @Rule ReportLogsOnFailure in our tests, we will be in the same situation and with the same polluted outputs on the CI. Were you able to investigate if it is possible to somehow hook into jUnit or ScalaTest runner?

@hubertp
Copy link
Collaborator Author

hubertp commented Aug 15, 2025

we will be in the same situation and with the same polluted outputs on the CI.

Quite the contrary. If this rule is not present, no logs would be printed.

Were you able to investigate if it is possible to somehow hook into jUnit or ScalaTest runner?

Hook into? To do what exactly?

@Akirathan
Copy link
Contributor

Akirathan commented Aug 15, 2025

Quite the contrary. If this rule is not present, no logs would be printed.

Can you elaborate? runtime-integration-tests/src/test/resources/application-test.conf specifies that the default appender is MemoryAppender which forwards to console. So if I implement a new test in runtime-integration-tests without any rules, the logs will still be forwarded to the console even if the test is successful, no? And what about tests in other projects? Like project-manager, language-server, etc?

Hook into? To do what exactly?

To do the same thing that you have implemented in the new rule - capture all output and only print it if a test failed.

In non-strict mode errors are being reported as warnings. Should
:fingers-crossed: help with CI failures.
@hubertp
Copy link
Collaborator Author

hubertp commented Aug 15, 2025

Can you elaborate? runtime-integration-tests/src/test/resources/application-test.conf specifies that the default appender is MemoryAppender which forwards to console. So if I implement a new test in runtime-integration-tests without any rules, the logs will still be forwarded to the console even if the test is successful, no?

No. The forwarding is manually requested. If you want to always see the logs you can change the default appender to console.

To do the same thing that you have implemented in the new rule - capture all output and only print it if a test failed.

Let's take it offline as I'm still missing the point.

@hubertp
Copy link
Collaborator Author

hubertp commented Aug 15, 2025

Can you elaborate? runtime-integration-tests/src/test/resources/application-test.conf specifies that the default appender is MemoryAppender which forwards to console. So if I implement a new test in runtime-integration-tests without any rules, the logs will still be forwarded to the console even if the test is successful, no?

No. The forwarding is manually requested. If you want to always see the logs you can change the default appender to console.

Reading it again, I feel that what you are asking makes sense. I remember that the reason why I didn't do it was because of some logs that could be reported prior to execution of any test cases, in setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collect logs in tests and only print them on failure

4 participants