test: Assert log warnings and errors - #8457
Conversation
|
After talking to @link2xt, we found some simplifications that are possible, and one bugfix that is needed:
|
8249945 to
2d7664d
Compare
66768b3 to
beedff7
Compare
71d806d to
f3df7e8
Compare
fe60a78 to
bbf432d
Compare
f892b0b to
3d6f761
Compare
3d6f761 to
9af2008
Compare
Hocuri
left a comment
There was a problem hiding this comment.
The only remaining point is the assert_many() function (see my comment there), then this is ready to be merged
| /// the first one takes precedence. | ||
| pub async fn assert_many(&self, mut assertions: Vec<(bool, &str, usize)>) { | ||
| 'events: while let Ok(Ok(event)) = | ||
| tokio::time::timeout(Duration::from_secs(1), self.events.recv()).await |
There was a problem hiding this comment.
This looks like it slows down every test assert_many by 1 second, because there is no break in the function body. For now that's fine because tests run in parallel anyways; in the future we should directly store the EventEmitter in InnerLogSink, rather than having a task (in the subscribe function) that takes the events out of one channel and writes them into another one. Then, we can probably use try_recv() here without the tests being flaky.
There was a problem hiding this comment.
Can you open an issue or PR for this?
4ead306 to
53e14ea
Compare
| /// the first one takes precedence. | ||
| pub async fn assert_many(&self, mut assertions: Vec<(bool, &str, usize)>) { | ||
| 'events: while let Ok(Ok(event)) = | ||
| tokio::time::timeout(Duration::from_secs(1), self.events.recv()).await |
There was a problem hiding this comment.
Can you open an issue or PR for this?
3d490b9 to
a5e8620
Compare
Adds `assert_warn`, `assert_error` and `assert_warns_or_errors` methods to `TestContext`, that let us assert that a certain warning or error is logged during the test. Also asserts test logs should not contain any other errors or warnings. Adjusts tests accordingly. Signed-off-by: Jagoda 艢l膮zak <jslazak@jslazak.com>
a5e8620 to
94b8c79
Compare
Adds
assert_warn,assert_errorandassert_warns_or_errorsmethods to
TestContext, that let us assert thata certain warning or error is logged during the test.
Also asserts test logs should not contain any other
errors or warnings.
Adjusts tests accordingly.