Skip to content

Support for parallel tests - #9

Merged
ansel1 merged 9 commits into
masterfrom
parallel
May 10, 2026
Merged

Support for parallel tests#9
ansel1 merged 9 commits into
masterfrom
parallel

Conversation

@ansel1

@ansel1 ansel1 commented May 10, 2026

Copy link
Copy Markdown
Contributor

Improves support for parallel tests in v2:

  • feat: flume v2 adds a new middleware and helper function for adding log attributes via the context. The helper attaches log attributes to a context object, and the middleware extract those attributes and adds them to log entries. For example: attach a request ID to the context object, and that request ID will be added to every log entry call when that context is passed to the log method.
  • fix: flumetest v2 didn't work with parallel tests: each test would start capturing the global log stream. Parallel tests would keep grabbing the log stream away from each other. Now, each test subscribes to the global log stream, allowing parallel tests to subscribe simultaneously. This does mean that individual log lines may appear in the log captures for multiple tests, and for any individual test, it will capture log lines which may not be related to that test's activities, but at least each test can guarantee that it has captured a full superset of the logs related to that test.
  • feat: flumetest v2 adds a new "Capture()" method, which is meant to supercede Start(). The only differences are:
    • It does not return a revert function. It exclusively uses t.Cleanup() to flush the log capture buffer. The does mean that in certain panic situations, the logs may be lost, but that is expected to be fixed in the golang SDK soon, and this makes Capture() much easier to embed in other test setup helper methods than Start().
    • It automatically installs the ContextAttrsMiddleware in the global slog handler, and returns a context.Context object (derived from t.Context()) which embeds the name of the test in it.

ansel1 and others added 9 commits April 30, 2026 15:45
Adds a logging middleware, and a contet helper.  The context
helper attaches arbitrary key/value attrs to contexts.  The
logging middleware adds any attributes attached to the context
to logging messages as logging attributes.
Replace per-test global-sink-swap with a fan-out multiplex writer
installed once on flume.Default(). Each Start() registers a subscriber
and captures logs during its active window.

Preserves nested-subtest semantics via lineage-aware suppression:
a child Start() suppresses ancestor captures for its window.

Verbose mode no longer live-streams to t.Log(); it now flushes
captured logs on success (in addition to failure).

Fixes parallel test log clobbering.
Does the same as Start(), with two changes:
- no revert function is returned.  Relies solely on t.Cleanup
- returns a context, which, if passed to slog logging methods, will
  add the test name to the log's attributes
@ansel1
ansel1 merged commit cdb10d3 into master May 10, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant