wasi: try to make Test_Nonblock less flaky (#1506)

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This commit is contained in:
Edoardo Vacchi
2023-06-05 23:04:39 +01:00
committed by GitHub
parent 62f8109101
commit 1d22d264d0
3 changed files with 12 additions and 3 deletions

View File

@@ -165,7 +165,7 @@ void main_sock() {
void main_nonblock(char* fpath) {
struct timespec tim, tim2;
tim.tv_sec = 0;
tim.tv_nsec = 200 * 1000000;
tim.tv_nsec = 100 * 1000000; // 100 msec
int fd = open(fpath, O_RDONLY | O_NONBLOCK);
char buf[32];
ssize_t newLen = 0;

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/testing/require"
)
@@ -26,8 +27,16 @@ func Test_Nonblock(t *testing.T) {
err := syscall.Mkfifo(fifoAbsPath, 0o666)
require.NoError(t, err)
ch := make(chan string, 1)
go func() { ch <- compileAndRun(t, testCtx, moduleConfig, wasmZigCc) }()
ch := make(chan string, 2)
go func() {
ch <- compileAndRunWithPreStart(t, testCtx, moduleConfig, wasmZigCc, func(t *testing.T, mod api.Module) {
// Send a dummy string to signal that initialization has completed.
ch <- "ready"
})
}()
// Wait for the dummy value, then start the sleep.
require.Equal(t, "ready", <-ch)
// The test writes a few dots on the console until the pipe has data ready for reading,
// so we wait for a little to ensure those dots are printed.