Skip to content

Commit

Permalink
fix(tests): address possible short leftpad write
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Sep 18, 2024
1 parent aadb6e9 commit 9cfa368
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/components/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ impl bindings::exports::west_test::leftpad::leftpad::Guest for Handler {
let rx: InputStream = in_.into_inner();
let tx: &OutputStream = out.get();

let mut cs = zip(0..len, iter::repeat(c)).map(|(_, c)| c);
let mut cs = zip(0..len, iter::repeat(c)).flat_map(|(_, c)| String::from(c).into_bytes());
let mut buf = Vec::default();
loop {
let mut n = tx.check_write()?;
if n == 0 {
tx.subscribe().block();
n = tx.check_write()?;
}
let s: Box<str> = cs
.by_ref()
.take(n.try_into().unwrap_or(usize::MAX) / c.len_utf8())
.collect();
if s.is_empty() {
buf.extend(cs.by_ref().take(n.try_into().unwrap_or(usize::MAX)));
if buf.is_empty() {
break;
}
tx.write(s.as_bytes())?;
tx.write(&buf)?;
buf.clear();
}
loop {
let n = tx.splice(&rx, 4096)?;
Expand Down

0 comments on commit 9cfa368

Please sign in to comment.