From 44d7c359469b987f7913c746f407c2a003a97858 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 4 Aug 2023 09:25:01 +0800 Subject: [PATCH] wasm: fixes test flake on Windows and strict mode 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 https://github.com/dapr/components-contrib/pull/2884#issuecomment-1664498860 Signed-off-by: Adrian Cole --- internal/wasm/wasm_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/wasm/wasm_test.go b/internal/wasm/wasm_test.go index 57379e7c72..be0276ab30 100644 --- a/internal/wasm/wasm_test.go +++ b/internal/wasm/wasm_test.go @@ -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, }, } @@ -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) }) } }