fix: Encoder state machine tolerates being wrapped by an AsyncWrite#309
fix: Encoder state machine tolerates being wrapped by an AsyncWrite#309aatifsyed wants to merge 7 commits intoNullus157:mainfrom
AsyncWrite#309Conversation
|
Thanks! You are right, poll_shutdown should indeed call self.poll_flush before calling inner.poll_shutdown |
1 similar comment
|
Thanks! You are right, poll_shutdown should indeed call self.poll_flush before calling inner.poll_shutdown |
AsyncWrite
| .with_span_events(FmtSpan::NEW) | ||
| .init(); | ||
| let mut zstd_encoder = Wrapper::new(Trace::new(ZstdEncoder::new(DelayedShutdown::default()))); | ||
| futures::executor::block_on(zstd_encoder.shutdown()).unwrap(); |
There was a problem hiding this comment.
I think we should test poll_shutdown by keeping track of numbers of calls to underlying poll_flush?
There was a problem hiding this comment.
I think that feels a bit excessive - we know that poll_shutdown has been called twice because of how DelayedShutdown is implemented (only returns Poll::Ready the second time), and that's what we really want to test.
i.e I don't think a change like this actually does anything for the test:
- let mut zstd_encoder = Wrapper::new(Trace::new(ZstdEncoder::new(DelayedShutdown::default())));
+ let mut delayed_shutdown = DelayedShutdown::default();
+ let mut zstd_encoder = Wrapper::new(Trace::new(ZstdEncoder::new(&mut delayed_shutdown)));
futures::executor::block_on(zstd_encoder.shutdown()).unwrap();
+ assert_eq!(delayed_shutdown.num_times_shutdown_called, 1);There was a problem hiding this comment.
I'd want the poll_flush to be tested, by making sure it is called if and only if poll_shutdown is called.
There was a problem hiding this comment.
:) could you help me write this test?
There was a problem hiding this comment.
Bit busy now, but in general, I think we want something like this:
struct DummyWriter {
is_poll_flush_called: boolean,
is_poll_shutdown_called: usize,
}
impl AsyncWrite {
fn poll_flush(...) {
assert!(!self.is_poll_shutdown_called);
self.is_poll_flush_called = true;
Ready(Ok())
}
fn poll_shutdown(...) {
self.is_poll_shutdown_called = true;
Ready(Ok())
}
}
And then after shutdown is called, we check that both is set to true to verify this fix.
|
What's the level of enthusiasm on this PR? |
I can continue review once the feedback has been addressed |
Simplified the
Encoderstate machine.It should now handle
poll_flushcalls afterpoll_shutdowncalls.Closes #308
See also #246