Commit c2e5772
authored
test: add nicer debug output to mock subscribers (#919)
## Motivation
The test-support mock subscribers currently `println!` a bunch of
debugging output. The debugging output is displayed if the test panics,
or if the test is run with `--nocapture`. This can be useful for
figuring out what went wrong if a test fails.
In some cases, tests involve multiple subscribers, to test behavior that
results from interactions between subscribers. In this case, there's no
way to tell which subscriber in the test the debug output came from.
Similarly, if a bunch of tests are run at the same time with
`--nocapture`, output from different test threads are interleaved,
making it impossible to interpret.
## Solution
This branch adds names to the mock subscribers, which are prepended to
their debugging output.
By default, the mock subscriber's name is the name of the test
(*technically*, the name of the thread where it was created, which is
the name of the test unless tests are run with `--test-threads=1`).
When a test has only one mock subscriber, this is sufficient. However,
some tests may include multiple subscribers, in order to test
interactions between multiple subscribers. In that case, it can be
helpful to give each subscriber a separate name to distinguish where the
debugging output comes from. Therefore, this branch also adds a `.named`
method to the mock subscriber builder, allowing them to be given custom
names in tests with more than one subscriber.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>1 parent fb4443f commit c2e5772
File tree
2 files changed
+129
-44
lines changed- tracing/tests
- support
2 files changed
+129
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
0 commit comments