-
Notifications
You must be signed in to change notification settings - Fork 35
wasi:[email protected]: Add tests for read/write/append #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
b04d3fe
to
7268371
Compare
7268371
to
1f37650
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I want to tag in @alexcrichton for this one because I'm not confident about subtleties of stream handling here.
(result, data) = rx.read(data).await; | ||
} | ||
StreamResult::Dropped => { | ||
assert_eq!(data.len(), bytes_read); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert may want to get deferred to the Ok
return value of this function because a short-read might happen due to an error and the error may want to get returned instead of panicking here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to understand the subtleties but I am a bit lost. If I understand you correctly, Dropped
can be accompanied by data, is that right? If so we should add an n
to Dropped
: bytecodealliance/wit-bindgen#1396. If not I think this assertion will never cause a failed pread, because bytes_read
and data.len()
are both incremented as part of Complete
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct that Dropped
can be accompanied by data, yeah. The lack of n
here is definitely an oversight and the assumption was that you'd look at the length of the buffer before/after to figure out the size (but then that's inconsistent with n
on StreamResult::Complete
, so n
should be on Dropped
and Cancelled
as well for consistency)
I think I actually confused myself about this assertion and what it originally meant. I thought it was somehow taking the size
parameter to the function into account but it isn't. Otherwise though you're also correct that this can panic in the case that Dropped
communicates some data, which wasn't actually what I was thinking about but is true nonetheless!
let (mut result, mut buf) = tx.write(data.to_vec()).await; | ||
loop { | ||
match result { | ||
StreamResult::Complete(n) => { | ||
assert!(n <= len - written); | ||
written += n; | ||
assert_eq!(buf.remaining(), len - written); | ||
if buf.remaining() != 0 { | ||
(result, buf) = tx.write_buf(buf).await; | ||
} else { | ||
break; | ||
} | ||
} | ||
StreamResult::Dropped => { | ||
panic!("receiver dropped the stream?"); | ||
} | ||
StreamResult::Cancelled => { | ||
break; | ||
} | ||
} | ||
} | ||
assert_eq!(buf.remaining(), len - written); | ||
drop(tx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be replacable with StreamWriter::write_all
perhaps? (plus an assert that the result of write_all
is empty)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW... I have been avoiding write_all
because I wanted to understand the stream mechanics. But, this is a WASI test suite, not a component model test suite, and so perhaps write_all
is the right thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True! Either way seems reasonable to me
I have granted @alexcrichton write privs so that his review of this makes it green. I think this is ready to go? |
No description provided.