Skip to content

Commit

Permalink
Context lint.
Browse files Browse the repository at this point in the history
Signed-off-by: Nuno Cruces <[email protected]>
  • Loading branch information
mathetake authored and ncruces committed Aug 14, 2024
1 parent 510568d commit 13797a8
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- 'netlify.toml'

env: # Update this prior to requiring a higher minor version in go.mod
GO_VERSION: "1.22"
GO_VERSION: "1.23"

defaults:
run: # use bash for all operating systems unless overridden
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

gofumpt := mvdan.cc/[email protected]
gosimports := github.com/rinchsan/gosimports/cmd/[email protected]
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.0
asmfmt := github.com/klauspost/asmfmt/cmd/[email protected]
# sync this with netlify.toml!
hugo := github.com/gohugoio/[email protected]
Expand Down
4 changes: 3 additions & 1 deletion experimental/close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/tetratelabs/wazero/internal/testing/require"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func TestWithCloseNotifier(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 3 additions & 1 deletion experimental/logging/log_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (
"github.com/tetratelabs/wazero/internal/wasm"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func Test_loggingListener(t *testing.T) {
wasiFuncName := wasi.RandomGetName
Expand Down
4 changes: 3 additions & 1 deletion experimental/sock/sock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/tetratelabs/wazero/internal/testing/require"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func TestWithSockConfig(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 3 additions & 1 deletion imports/assemblyscript/assemblyscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"github.com/tetratelabs/wazero/sys"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func TestAbort(t *testing.T) {
tests := []struct {
Expand Down
4 changes: 3 additions & 1 deletion imports/emscripten/emscripten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ var growWasm []byte
//go:embed testdata/invoke.wasm
var invokeWasm []byte

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

// TestGrow is an integration test until we have an Emscripten example.
func TestGrow(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion imports/wasi_snapshot_preview1/wasi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"github.com/tetratelabs/wazero/sys"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

const testMemoryPageSize = 1

Expand Down
4 changes: 3 additions & 1 deletion internal/engine/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"github.com/tetratelabs/wazero/internal/wasm"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func TestInterpreter_peekValues(t *testing.T) {
ce := &callEngine{}
Expand Down
4 changes: 3 additions & 1 deletion internal/integration_test/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/tetratelabs/wazero/internal/platform"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

// caseWasm was compiled from TinyGo testdata/case.go
//
Expand Down
7 changes: 5 additions & 2 deletions internal/integration_test/engine/adhoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ func TestEngineInterpreter(t *testing.T) {
runAllTests(t, tests, wazero.NewRuntimeConfigInterpreter().WithCloseOnContextDone(true), false)
}

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

const i32, i64, f32, f64, v128 = wasm.ValueTypeI32, wasm.ValueTypeI64, wasm.ValueTypeF32, wasm.ValueTypeF64, wasm.ValueTypeV128

Expand Down Expand Up @@ -406,7 +408,8 @@ func testHostFuncMemory(t *testing.T, r wazero.Runtime) {

// testNestedGoContext ensures context is updated when a function calls another.
func testNestedGoContext(t *testing.T, r wazero.Runtime) {
nestedCtx := context.WithValue(context.Background(), struct{}{}, "nested")
type arbitrary struct{}
nestedCtx := context.WithValue(context.Background(), arbitrary{}, "arbitrary")

importedName := t.Name() + "-imported"
importingName := t.Name() + "-importing"
Expand Down
4 changes: 3 additions & 1 deletion internal/wasm/gofunc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/tetratelabs/wazero/internal/testing/require"
)

type arbitrary struct{}

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
var testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")

func Test_parseGoFunc(t *testing.T) {
tests := []struct {
Expand Down
12 changes: 8 additions & 4 deletions internal/wasm/module_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func TestModuleInstance_CloseModuleOnCanceledOrTimeout(t *testing.T) {
const duration = time.Second
ctx, cancel := context.WithTimeout(context.Background(), duration)
defer cancel()
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, struct{}{}, 1)) // Wrapping arbitrary context.
type arbitrary struct{}
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, arbitrary{}, "arbitrary")) // Wrapping arbitrary context.
time.Sleep(duration * 2)
defer done()

Expand All @@ -285,7 +286,8 @@ func TestModuleInstance_CloseModuleOnCanceledOrTimeout(t *testing.T) {
t.Run("cancel", func(t *testing.T) {
cc := &ModuleInstance{ModuleName: "test", s: s, Sys: internalsys.DefaultContext(nil)}
ctx, cancel := context.WithCancel(context.Background())
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, struct{}{}, 1)) // Wrapping arbitrary context.
type arbitrary struct{}
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, arbitrary{}, "arbitrary")) // Wrapping arbitrary context.
cancel()
// Make sure nothing panics or otherwise gets weird with redundant call to cancel().
cancel()
Expand All @@ -312,7 +314,8 @@ func TestModuleInstance_CloseModuleOnCanceledOrTimeout(t *testing.T) {
// Wrap the cancel context by timeout.
ctx, cancel = context.WithTimeout(ctx, duration)
defer cancel()
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, struct{}{}, 1)) // Wrapping arbitrary context.
type arbitrary struct{}
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, arbitrary{}, "arbitrary")) // Wrapping arbitrary context.
time.Sleep(duration * 2)
defer done()

Expand All @@ -335,7 +338,8 @@ func TestModuleInstance_CloseModuleOnCanceledOrTimeout(t *testing.T) {
ctx, timeoutDone = context.WithTimeout(ctx, time.Second*1000)
defer timeoutDone()

done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, struct{}{}, 1)) // Wrapping arbitrary context.
type arbitrary struct{}
done := cc.CloseModuleOnCanceledOrTimeout(context.WithValue(ctx, arbitrary{}, "arbitrary")) // Wrapping arbitrary context.
cancel()
defer done()

Expand Down
4 changes: 3 additions & 1 deletion runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"github.com/tetratelabs/wazero/sys"
)

type arbitrary struct{}

var (
binaryNamedZero = binaryencoding.EncodeModule(&wasm.Module{NameSection: &wasm.NameSection{ModuleName: "0"}})
// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
testCtx = context.WithValue(context.Background(), arbitrary{}, "arbitrary")
)

var _ context.Context = &HostContext{}
Expand Down

0 comments on commit 13797a8

Please sign in to comment.