Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information