Skip to content

Commit

Permalink
wasm: fixes test flake on Windows and strict mode
Browse files Browse the repository at this point in the history
Windows clocks often don't give microsecond scope reading reliably. Our
"strict mode" test was accidentally verifying a lower bound of time
spent sleeping, when the important part is the upper bound. This removes
the lower bound, so that tests pass on both unix and windows.

See #2884 (comment)

Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Aug 4, 2023
1 parent 46b7535 commit 44d7c35
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/wasm/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,14 @@ func TestNewModuleConfig(t *testing.T) {
maxDuration: 50 * time.Millisecond * 5,
},
{
name: "strictSandbox = true",
metadata: &InitMetadata{StrictSandbox: true, Guest: binStrict},
minDuration: 10 * time.Microsecond,
name: "strictSandbox = true",
metadata: &InitMetadata{StrictSandbox: true, Guest: binStrict},
// In strict mode, nanosleep is implemented by an incrementing
// number. The resolution of the real clock timing the wasm
// invocation is lower resolution in Windows, so we can't verify a
// lower bound. In any case, the important part is that we aren't
// actually sleeping 50ms, which is what wasm thinks is happening.
minDuration: 0,
maxDuration: 1 * time.Millisecond,
},
}
Expand Down Expand Up @@ -211,7 +216,8 @@ func TestNewModuleConfig(t *testing.T) {
} else {
require.NotEqual(t, deterministicOut, out.String())
}
require.True(t, duration > tc.minDuration && duration < tc.maxDuration, duration)
require.GreaterOrEqual(t, duration, tc.minDuration)
require.LessOrEqual(t, duration, tc.maxDuration)
})
}
}

0 comments on commit 44d7c35

Please sign in to comment.