multi: context.Background() -> t.Context()

Use the new feature of Go 1.24, fix linter warnings.

This change was produced by:
 - running golangci-lint run --fix
 - sed 's/context.Background/t.Context/' -i `git grep -l context.Background | grep test.go`
 - manually fixing broken tests
 - itest, lntest: use ht.Context() where ht or hn is available
 - in HarnessNode.Stop() we keep using context.Background(), because it is
   called from a cleanup handler in which t.Context() is canceled already.
This commit is contained in:
Boris Nagaev committed 2025-08-30 14:13:44 -03:00
1 parent 6ffe257004
commit dee8ad3754
71 files changed
+361 -393

No files matched your search

+10 -10
View File
@@ -20,7 +20,7 @@ func TestContextGuard(t *testing.T) {
t.Run("Parent context is cancelled", func(t *testing.T) {
t.Parallel()
var (
ctx, cancel = context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(t.Context())
g = NewContextGuard()
)
@@ -42,7 +42,7 @@ func TestContextGuard(t *testing.T) {
t.Run("Derived context is cancelled", func(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
)
@@ -66,7 +66,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
)
ctxc, _ := g.Create(ctx)
@@ -87,7 +87,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx, cancel = context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(t.Context())
g = NewContextGuard()
)
cancel()
@@ -107,7 +107,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
)
@@ -130,7 +130,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx, cancel = context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(t.Context())
g = NewContextGuard()
task = make(chan struct{})
done = make(chan struct{})
@@ -172,7 +172,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
task = make(chan struct{})
done = make(chan struct{})
@@ -218,7 +218,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
task = make(chan struct{})
done = make(chan struct{})
@@ -316,7 +316,7 @@ func TestContextGuard(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
g = NewContextGuard()
task = make(chan struct{})
done = make(chan struct{})
@@ -452,7 +452,7 @@ func TestContextGuardCountGoroutines(t *testing.T) {
g := NewContextGuard()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
// Count goroutines before contexts are created.
count1 := runtime.NumGoroutine()
+3 -3
View File
@@ -18,7 +18,7 @@ func TestGoroutineManager(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
m = NewGoroutineManager()
taskChan = make(chan struct{})
)
@@ -61,7 +61,7 @@ func TestGoroutineManager(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
m = NewGoroutineManager()
taskChan = make(chan struct{})
)
@@ -114,7 +114,7 @@ func TestGoroutineManager(t *testing.T) {
t.Parallel()
var (
ctx = context.Background()
ctx = t.Context()
m = NewGoroutineManager()
stopChan = make(chan struct{})
)