Skip to content

Commit

Permalink
Fix a race condition in some tests
Browse files Browse the repository at this point in the history
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 bytecodealliance#1820
  • Loading branch information
alexcrichton committed Sep 25, 2024
1 parent 51ade65 commit 5eca941
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 28 deletions.
6 changes: 4 additions & 2 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ fn execute(cmd: &mut Command, stdin: Option<&[u8]>, should_fail: bool) -> Result

let mut io = p.stdin.take().unwrap();
if let Some(stdin) = stdin {
io.write_all(stdin)?;
io.write_all(stdin).context("failed to write to stdin")?;
}
drop(io);

let output = p.wait_with_output()?;
let output = p
.wait_with_output()
.context("failed to wait for process exit")?;

let mut failure = None;
match output.status.code() {
Expand Down
12 changes: 12 additions & 0 deletions tests/cli/unbundle-print-module.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; RUN[gen]: component unbundle --threshold 0 % --module-dir %tmpdir
;; RUN[read0]: print %tmpdir/unbundled-module0.wasm
;; RUN[read1]: print %tmpdir/unbundled-module1.wasm

(component
(core module $a
(import "a" "a" (func))
)
(core module $b
(import "b" "b" (func))
)
)
Binary file added tests/cli/unbundle-print-module.wat.gen.stdout
Binary file not shown.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions tests/cli/unbundle-print-module0.wat

This file was deleted.

10 changes: 0 additions & 10 deletions tests/cli/unbundle-print-module1.wat

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
// RUN[gen]: component wit % --out-dir %tmpdir
// RUN[read]: component wit %tmpdir

package foo:root;
package a:b@0.2.0 {
Expand All @@ -14,4 +15,4 @@ package a:c {
import a:b/foo@0.2.0;
import a:b/foo;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Writing: %tmpdir/deps/b.wit
Writing: %tmpdir/deps/b@0.2.0.wit
Writing: %tmpdir/deps/c.wit
Writing: %tmpdir/root.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
/// RUN[gen]: component wit % --out-dir %tmpdir
/// RUN[read]: component wit %tmpdir
package foo:root;

package a:b {
Expand Down
5 changes: 3 additions & 2 deletions tests/cli/wit-directory-output-valid.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
// RUN[gen]: component wit % --out-dir %tmpdir
// RUN[read]: component wit %tmpdir

package foo:root;
package a:b {
Expand All @@ -12,4 +13,4 @@ package a:b {

package a:c {
interface foo {}
}
}
3 changes: 3 additions & 0 deletions tests/cli/wit-directory-output-valid.wit.gen.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Writing: %tmpdir/deps/c.wit
Writing: %tmpdir/deps/b.wit
Writing: %tmpdir/root.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// RUN: component wit % --out-dir %tmpdir | component wit %tmpdir
/// RUN[gen]: component wit % --out-dir %tmpdir
/// RUN[read]: component wit %tmpdir
package foo:root;

package a:c {
Expand Down

0 comments on commit 5eca941

Please sign in to comment.