Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ version: "2"
linters:
default: none
enable:
- contextcheck
- copyloopvar
- errcheck
- intrange
- mirror
- perfsprint
- usestdlibvars
- usetesting # Reports uses of functions with replacement inside the testing package.

settings:
usetesting:
context-background: true
context-todo: true

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
10 changes: 5 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func TestNewIsLazyAndResolvesTypedGeneratedClient(t *testing.T) {
assert.NilError(t, err)
assert.Assert(t, greeterConn == echoConn, "all configured points must share one private connection")

reply, err := greeter.Greet(context.Background(), &greeterv0.HelloRequest{Name: "world"})
reply, err := greeter.Greet(t.Context(), &greeterv0.HelloRequest{Name: "world"})
assert.NilError(t, err)
assert.Equal(t, reply.Message, "hello world")
response, err := echo.Echo(context.Background(), &echov1.EchoRequest{Message: "round trip"})
response, err := echo.Echo(t.Context(), &echov1.EchoRequest{Message: "round trip"})
assert.NilError(t, err)
assert.Equal(t, response.Message, "round trip")
assert.Equal(t, engine.dials.Load(), int64(1), "the shared lazy connection should dial once")
Expand All @@ -157,7 +157,7 @@ func TestNewFreezesRegistrations(t *testing.T) {
}
provider, err := Resolve(client, point)
assert.NilError(t, err)
reply, err := provider.Greet(context.Background(), &greeterv0.HelloRequest{Name: "world"})
reply, err := provider.Greet(t.Context(), &greeterv0.HelloRequest{Name: "world"})
assert.NilError(t, err)
assert.Equal(t, reply.Message, "first")
assert.Equal(t, engine.dials.Load(), int64(0))
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestResolveConcurrentProviderAndMethodCalls(t *testing.T) {
results <- err
return
}
reply, err := provider.Greet(context.Background(), &greeterv0.HelloRequest{Name: "concurrent"})
reply, err := provider.Greet(t.Context(), &greeterv0.HelloRequest{Name: "concurrent"})
if err != nil {
results <- err
return
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestCloseIsIdempotentAndClosesPrivateConnection(t *testing.T) {
assert.NilError(t, err)
provider, err := Resolve(client, greeterv0.Point)
assert.NilError(t, err)
_, err = provider.Greet(context.Background(), &greeterv0.HelloRequest{Name: "close"})
_, err = provider.Greet(t.Context(), &greeterv0.HelloRequest{Name: "close"})
assert.NilError(t, err)
conn := <-engine.conns

Expand Down
4 changes: 2 additions & 2 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestSingleSelection(t *testing.T) {
resolvedProvider("org.mobyproject.stock.v1", ExtensionOriginBuiltin, stock),
))
assert.NilError(t, err)
assert.NilError(t, got.Call(context.Background()), "the default must stand in when nothing is installed")
assert.NilError(t, got.Call(t.Context()), "the default must stand in when nothing is installed")
})

t.Run("executable provider masks the builtin", func(t *testing.T) {
Expand All @@ -211,7 +211,7 @@ func TestSingleSelection(t *testing.T) {
resolvedProvider("org.example.custom.v1", ExtensionOriginExecutable, customC),
))
assert.NilError(t, err)
assert.NilError(t, got.Call(context.Background()))
assert.NilError(t, got.Call(t.Context()))
assert.Equal(t, called, "custom", "the executable provider must replace the builtin, not conflict with it")
})

Expand Down
14 changes: 7 additions & 7 deletions fanout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestEachBoundsEveryProviderIndependently(t *testing.T) {
return nil
})

err := Each(context.Background(), testPoint, resolverOf(
err := Each(t.Context(), testPoint, resolverOf(
resolvedProvider("slow", ExtensionOriginExecutable, slow),
resolvedProvider("second", ExtensionOriginExecutable, record),
), Policy{Timeout: timeout}, func(ctx context.Context, c caller) error {
Expand All @@ -50,7 +50,7 @@ func TestEachAbortsOnErrorAndAttributes(t *testing.T) {
count := callerFunc(func(context.Context) error { called++; return nil })
veto := callerFunc(func(context.Context) error { called++; return errors.New("not allowed") })

err := Each(context.Background(), testPoint, resolverOf(
err := Each(t.Context(), testPoint, resolverOf(
resolvedProvider("org.example.veto.v1", ExtensionOriginExecutable, veto),
resolvedProvider("org.example.after.v1", ExtensionOriginExecutable, count),
), Policy{Action: "vetoed the start"}, func(ctx context.Context, c caller) error {
Expand All @@ -66,7 +66,7 @@ func TestEachFailOpenSkipsAndContinues(t *testing.T) {
count := callerFunc(func(context.Context) error { called++; return nil })
boom := callerFunc(func(context.Context) error { called++; return errors.New("boom") })

err := Each(context.Background(), testPoint, resolverOf(
err := Each(t.Context(), testPoint, resolverOf(
resolvedProvider("org.example.broken.v1", ExtensionOriginExecutable, boom),
resolvedProvider("org.example.ok.v1", ExtensionOriginExecutable, count),
), Policy{FailOpen: true}, func(ctx context.Context, c caller) error {
Expand All @@ -79,7 +79,7 @@ func TestEachFailOpenSkipsAndContinues(t *testing.T) {

func TestFoldThreadsValueInOrder(t *testing.T) {
noop := callerFunc(func(context.Context) error { return nil })
out, err := Fold(context.Background(), testPoint, resolverOf(
out, err := Fold(t.Context(), testPoint, resolverOf(
resolvedProvider("a", ExtensionOriginExecutable, noop),
resolvedProvider("b", ExtensionOriginExecutable, noop),
), Policy{}, "seed", func(_ context.Context, _ caller, acc string) (string, error) {
Expand All @@ -90,11 +90,11 @@ func TestFoldThreadsValueInOrder(t *testing.T) {
}

func TestFoldDiscardsPartialValueOnError(t *testing.T) {
out, err := Fold(context.Background(), testPoint, resolverOf(
out, err := Fold(t.Context(), testPoint, resolverOf(
resolvedProvider("a", ExtensionOriginExecutable, callerFunc(func(context.Context) error { return nil })),
resolvedProvider("b", ExtensionOriginExecutable, callerFunc(func(context.Context) error { return errors.New("no") })),
), Policy{}, "seed", func(_ context.Context, c caller, acc string) (string, error) {
if err := c.Call(context.Background()); err != nil {
), Policy{}, "seed", func(ctx context.Context, c caller, acc string) (string, error) {
if err := c.Call(ctx); err != nil {
return acc, err
}
return acc + "+", nil
Expand Down
13 changes: 6 additions & 7 deletions grpcproxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var streamerDesc = grpc.ServiceDesc{
}

func TestProxyServerStreaming(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()

backendSock := filepath.Join(shortTempDir(t), "backend.sock")
Expand Down Expand Up @@ -99,7 +99,7 @@ var unaryDesc = grpc.ServiceDesc{
}

func TestProxyUnary(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()

clientConn := startProxy(t, "test.Unary", func(s *grpc.Server) { s.RegisterService(&unaryDesc, nil) })
Expand All @@ -126,7 +126,7 @@ var statusDesc = grpc.ServiceDesc{
}

func TestProxyForwardsBackendStatus(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()

clientConn := startProxy(t, "test.Status", func(s *grpc.Server) { s.RegisterService(&statusDesc, nil) })
Expand Down Expand Up @@ -157,7 +157,7 @@ var metaDesc = grpc.ServiceDesc{
}

func TestProxyForwardsMetadata(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()

clientConn := startProxy(t, "test.Meta", func(s *grpc.Server) { s.RegisterService(&metaDesc, nil) })
Expand Down Expand Up @@ -196,7 +196,7 @@ var collectorDesc = grpc.ServiceDesc{
}

func TestProxyClientStreaming(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()

clientConn := startProxy(t, "test.Collector", func(s *grpc.Server) { s.RegisterService(&collectorDesc, nil) })
Expand Down Expand Up @@ -249,8 +249,7 @@ func serve(t *testing.T, sock string, register func(*grpc.Server)) grpc.ClientCo

func shortTempDir(t *testing.T) string {
t.Helper()
// Keep socket paths relative so they fit Windows' AF_UNIX path limit.
dir, err := os.MkdirTemp(".", "m")
dir, err := os.MkdirTemp(".", "m") //nolint:usetesting // Keep socket paths relative so they fit Windows' AF_UNIX path limit.
assert.NilError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(dir) })
return dir
Expand Down
7 changes: 3 additions & 4 deletions host/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func extensionBinaryPath(dir, id string) string {

func shortTempDir(t *testing.T) string {
t.Helper()
// Keep socket paths relative so they fit Windows' AF_UNIX path limit.
dir, err := os.MkdirTemp(".", "m")
dir, err := os.MkdirTemp(".", "m") //nolint:usetesting // Keep socket paths relative so they fit Windows' AF_UNIX path limit.
assert.NilError(t, err)
t.Cleanup(func() { _ = os.RemoveAll(dir) })
return dir
Expand All @@ -57,7 +56,7 @@ func TestOutOfProcessDependency(t *testing.T) {
t.Fatalf("build greeterdep extension: %v\n%s", err, out)
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
defer cancel()

var calls atomic.Int32
Expand All @@ -73,7 +72,7 @@ func TestOutOfProcessDependency(t *testing.T) {
host.WithDependencyProviders(greeterpb.ServerPoint),
)
assert.NilError(t, err)
defer func() { assert.NilError(t, h.Shutdown(context.Background())) }()
defer func() { assert.NilError(t, h.Shutdown(context.WithoutCancel(ctx))) }()

assert.Equal(t, calls.Load(), int32(1),
"in-process greeter provider was not called by the out-of-process extension")
Expand Down
7 changes: 4 additions & 3 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,9 @@ func New(ctx context.Context, optionList ...Option) (_ *Host, retErr error) {
// also explicitly close loaded resources.
defer func() {
if retErr != nil {
_ = b.Shutdown(context.Background())
closeLoaded(context.Background(), loaded)
ctx := context.WithoutCancel(ctx)
_ = b.Shutdown(ctx)
closeLoaded(ctx, loaded)
if callback != nil {
callback.Stop()
}
Expand Down Expand Up @@ -676,7 +677,7 @@ func loadProcess(ctx context.Context, l launcher.Launcher, bin string, providers
owned := true
defer func() {
if owned {
_ = launched.Close(context.Background())
_ = launched.Close(context.WithoutCancel(ctx))
}
}()

Expand Down
Loading
Loading