Skip to content

Commit 299ee90

Browse files
committed
check stderr instead
1 parent 374dc19 commit 299ee90

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

tests/componentize.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,25 @@ fn http_example() -> anyhow::Result<()> {
7777
let mut handle = std::process::Command::new("wasmtime")
7878
.current_dir(&path)
7979
.args(["serve", "--wasi", "common", "http.wasm"])
80-
.stdout(Stdio::piped())
80+
.stderr(Stdio::piped())
8181
.spawn()?;
8282

83-
let mut buf = [0; 64];
84-
let mut stdout = handle.stdout.take().unwrap();
83+
let mut buf = [0; 36];
84+
let mut stderr = handle.stderr.take().unwrap();
8585

86-
// Read at least one byte from stdout
87-
retry(|| -> anyhow::Result<()> {
88-
if buf.is_empty() && stdout.read(&mut buf)? == 0 {
89-
return Err(anyhow::anyhow!("No data"));
90-
}
91-
Ok(())
92-
})?;
86+
// Read until "Serving HTTP" shows up
87+
retry(
88+
|| -> anyhow::Result<()> {
89+
if stderr.read(&mut buf)? == 0 {
90+
return Err(anyhow::anyhow!("No data"));
91+
}
92+
if !String::from_utf8(buf.to_vec())?.contains("Serving HTTP on http://0.0.0.0:8080/") {
93+
return Err(anyhow::anyhow!("Wrong output"));
94+
}
95+
Ok(())
96+
},
97+
10,
98+
)?;
9399

94100
let content = "’Twas brillig, and the slithy toves
95101
Did gyre and gimble in the wabe:
@@ -109,7 +115,7 @@ All mimsy were the borogoves,
109115
.text()?)
110116
};
111117

112-
let text = retry(echo)?;
118+
let text = retry(echo, 5)?;
113119
assert!(text.ends_with(&content));
114120

115121
let hash_all = || -> anyhow::Result<String> {
@@ -123,7 +129,7 @@ All mimsy were the borogoves,
123129
.text()?)
124130
};
125131

126-
let text = retry(hash_all)?;
132+
let text = retry(hash_all, 5)?;
127133
assert!(text.contains("https://webassembly.github.io/spec/core/:"));
128134
assert!(text.contains("https://bytecodealliance.org/:"));
129135
assert!(text.contains("https://www.w3.org/groups/wg/wasm/:"));
@@ -284,14 +290,14 @@ fn tcp_example() -> anyhow::Result<()> {
284290
Ok(())
285291
}
286292

287-
fn retry<T>(mut func: impl FnMut() -> anyhow::Result<T>) -> anyhow::Result<T> {
288-
for i in 0..5 {
293+
fn retry<T>(mut func: impl FnMut() -> anyhow::Result<T>, times: usize) -> anyhow::Result<T> {
294+
for i in 0..times {
289295
match func() {
290296
Ok(t) => {
291297
return Ok(t);
292298
}
293299
Err(err) => {
294-
if i == 4 {
300+
if i == times - 1 {
295301
return Err(err);
296302
} else {
297303
sleep(Duration::from_secs(1));

0 commit comments

Comments
 (0)