Skip to content

Commit cc4c95c

Browse files
authored
Fix a race condition in some tests (#1821)
Some tests were modeled as "do a thing piped into another thing" but the second command didn't actually take any input. That meant that writing the stdout of the previous command into the next command might sometimes fail if the second command finishes before the write finishes. This commit fixes the various affected tests with the now-added ability to run multiple separate commands in a single file. These failures were detected by inserting a `sleep` before writing stdin and then fixing all tests. Closes #1820
1 parent 76c0c48 commit cc4c95c

13 files changed

+33
-28
lines changed

tests/cli.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ fn execute(cmd: &mut Command, stdin: Option<&[u8]>, should_fail: bool) -> Result
161161

162162
let mut io = p.stdin.take().unwrap();
163163
if let Some(stdin) = stdin {
164-
io.write_all(stdin)?;
164+
io.write_all(stdin).context("failed to write to stdin")?;
165165
}
166166
drop(io);
167167

168-
let output = p.wait_with_output()?;
168+
let output = p
169+
.wait_with_output()
170+
.context("failed to wait for process exit")?;
169171

170172
let mut failure = None;
171173
match output.status.code() {

tests/cli/unbundle-print-module.wat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; RUN[gen]: component unbundle --threshold 0 % --module-dir %tmpdir
2+
;; RUN[read0]: print %tmpdir/unbundled-module0.wasm
3+
;; RUN[read1]: print %tmpdir/unbundled-module1.wasm
4+
5+
(component
6+
(core module $a
7+
(import "a" "a" (func))
8+
)
9+
(core module $b
10+
(import "b" "b" (func))
11+
)
12+
)
133 Bytes
Binary file not shown.

tests/cli/unbundle-print-module0.wat

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/cli/unbundle-print-module1.wat

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/cli/wit-directory-output-in-deps-folder-with-multiple-version.wit

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
1+
// RUN[gen]: component wit % --out-dir %tmpdir
2+
// RUN[read]: component wit %tmpdir
23

34
package foo:root;
45
package a:b@0.2.0 {
@@ -14,4 +15,4 @@ package a:c {
1415
import a:b/foo@0.2.0;
1516
import a:b/foo;
1617
}
17-
}
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Writing: %tmpdir/deps/b.wit
2+
Writing: %tmpdir/deps/[email protected]
3+
Writing: %tmpdir/deps/c.wit
4+
Writing: %tmpdir/root.wit

tests/cli/wit-directory-output-in-deps-folder-with-multiple-version.wit.stdout renamed to tests/cli/wit-directory-output-in-deps-folder-with-multiple-version.wit.read.stdout

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
1+
/// RUN[gen]: component wit % --out-dir %tmpdir
2+
/// RUN[read]: component wit %tmpdir
23
package foo:root;
34

45
package a:b {

0 commit comments

Comments
 (0)