From 8905c3052bf4a76fd840c8556c4860220193ce64 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 25 Sep 2025 19:27:55 +0200 Subject: [PATCH] daemon/libnetwork: use t.Context() in tests Signed-off-by: Sebastiaan van Stijn --- daemon/libnetwork/drivers/windows/windows_test.go | 2 +- daemon/libnetwork/libnetwork_linux_test.go | 4 ++-- daemon/libnetwork/network_windows_test.go | 3 +-- daemon/libnetwork/networkdb/networkdb_test.go | 7 ++++--- daemon/libnetwork/osl/kernel/knobs_linux_test.go | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/daemon/libnetwork/drivers/windows/windows_test.go b/daemon/libnetwork/drivers/windows/windows_test.go index cee7ff375d..8fad7af610 100644 --- a/daemon/libnetwork/drivers/windows/windows_test.go +++ b/daemon/libnetwork/drivers/windows/windows_test.go @@ -46,7 +46,7 @@ func testNetwork(networkType string, t *testing.T) { epOptions := make(map[string]any) te := &testEndpoint{} - err = d.CreateEndpoint(context.TODO(), "dummy", "ep1", te.Interface(), epOptions) + err = d.CreateEndpoint(t.Context(), "dummy", "ep1", te.Interface(), epOptions) if err != nil { t.Fatalf("Failed to create an endpoint : %s", err.Error()) } diff --git a/daemon/libnetwork/libnetwork_linux_test.go b/daemon/libnetwork/libnetwork_linux_test.go index 4e0493175d..f7f1c56922 100644 --- a/daemon/libnetwork/libnetwork_linux_test.go +++ b/daemon/libnetwork/libnetwork_linux_test.go @@ -437,7 +437,7 @@ func TestNetworkEndpointsWalkers(t *testing.T) { assert.Assert(t, epWanted != nil) assert.Assert(t, is.Equal(epWanted, ep11)) - ctx := context.TODO() + ctx := t.Context() current := len(controller.Networks(ctx)) // Create network 2 @@ -1262,7 +1262,7 @@ func externalKeyTest(t *testing.T, reexec bool) { assert.NilError(t, err, "Failed to create new osl sandbox") defer func() { if err := extOsBox.Destroy(); err != nil { - log.G(context.TODO()).Warnf("Failed to remove os sandbox: %v", err) + log.G(t.Context()).Warnf("Failed to remove os sandbox: %v", err) } }() diff --git a/daemon/libnetwork/network_windows_test.go b/daemon/libnetwork/network_windows_test.go index e606931d1d..e5f7ca7284 100644 --- a/daemon/libnetwork/network_windows_test.go +++ b/daemon/libnetwork/network_windows_test.go @@ -1,7 +1,6 @@ package libnetwork import ( - "context" "fmt" "net" "net/netip" @@ -176,7 +175,7 @@ func TestAddEpToResolver(t *testing.T) { } // Add the endpoint and check expected results. - err := addEpToResolverImpl(context.TODO(), + err := addEpToResolverImpl(t.Context(), "netname", "epname", tc.epToAdd, resolvers, tc.hnsEndpoints) assert.Check(t, err) for i, resolver := range resolvers { diff --git a/daemon/libnetwork/networkdb/networkdb_test.go b/daemon/libnetwork/networkdb/networkdb_test.go index c1cadeea88..a63de7e9df 100644 --- a/daemon/libnetwork/networkdb/networkdb_test.go +++ b/daemon/libnetwork/networkdb/networkdb_test.go @@ -38,6 +38,7 @@ type TestingT interface { assert.TestingT poll.TestingT Helper() + Context() context.Context } func launchNode(t TestingT, conf Config) *NetworkDB { @@ -82,7 +83,7 @@ func createNetworkDBInstances(t TestingT, num int, namePrefix string, conf *Conf func closeNetworkDBInstances(t TestingT, dbs []*NetworkDB) { t.Helper() - log.G(context.TODO()).Print("Closing DB instances...") + log.G(t.Context()).Print("Closing DB instances...") for _, db := range dbs { db.Close() } @@ -923,7 +924,7 @@ func TestNetworkDBIslands(t *testing.T) { // Now the 3 bootstrap nodes will cleanly leave, and will be properly removed from the other 2 nodes for i := 0; i < 3; i++ { - log.G(context.TODO()).Infof("node %d leaving", i) + log.G(t.Context()).Infof("node %d leaving", i) dbs[i].Close() } @@ -958,7 +959,7 @@ func TestNetworkDBIslands(t *testing.T) { // Spawn again the first 3 nodes with different names but same IP:port for i := 0; i < 3; i++ { - log.G(context.TODO()).Infof("node %d coming back", i) + log.G(t.Context()).Infof("node %d coming back", i) conf := *dbs[i].config conf.NodeID = stringid.TruncateID(stringid.GenerateRandomID()) dbs[i] = launchNode(t, conf) diff --git a/daemon/libnetwork/osl/kernel/knobs_linux_test.go b/daemon/libnetwork/osl/kernel/knobs_linux_test.go index c1e2163570..62d7649241 100644 --- a/daemon/libnetwork/osl/kernel/knobs_linux_test.go +++ b/daemon/libnetwork/osl/kernel/knobs_linux_test.go @@ -1,7 +1,6 @@ package kernel import ( - "context" "testing" "github.com/containerd/log" @@ -18,7 +17,7 @@ func TestReadWriteKnobs(t *testing.T) { // Check if the test is able to read the value v, err := readSystemProperty(k) if err != nil { - log.G(context.TODO()).WithError(err).Warnf("Path %v not readable", k) + log.G(t.Context()).WithError(err).Warnf("Path %v not readable", k) // the path is not there, skip this key continue }