Skip to content

StreamInterceptor should/could use InheritableThreadLocal #3231

@mikehearn

Description

@mikehearn

As documented, JUnit loses stdout (and therefore log lines) when execution crosses into a new thread inside a test. This can be confusing because the printed text just disappears, which is unintuitive.

The stated rationale is that "it would be impossible to attribute [the output] to a specific test or container". Whilst there's no general way to do it:

  • It would be better to just emit to stdout directly if it can't be properly captured rather than losing the printing.
  • Using InheritableThreadLocal will handle the common case where code starts a thread as part of its work and then shuts the thread down, as that way the underlying RewindableByteArrayOutputStream will be propagated.

In theory (!) it's a simple enough change. As well as changing the TLS slot type, the RewindableByteArrayOutputStream needs to be made thread safe.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions