Close and return immediately if the context is already canceled (#1158)

Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
Co-authored-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
This commit is contained in:
Clifton Kaznocha
2023-02-23 17:58:07 -08:00
committed by GitHub
parent f0132ee346
commit ecb5b1ad03
5 changed files with 85 additions and 7 deletions

View File

@@ -117,6 +117,15 @@ func testEnsureTerminationOnClose(t *testing.T, r wazero.Runtime) {
require.Contains(t, err.Error(), fmt.Sprintf("module \"%s\" closed with context canceled", t.Name()))
})
t.Run("context cancel in advance", func(t *testing.T) {
_, infinite := newInfiniteLoopFn(t)
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err = infinite.Call(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), fmt.Sprintf("module \"%s\" closed with context canceled", t.Name()))
})
t.Run("context timeout", func(t *testing.T) {
_, infinite := newInfiniteLoopFn(t)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)