@cryptotaxi247 / kubo / commits / 3f2cc50eb

refactor: replace context.WithCancel with t.Context (#11083)

Signed-off-by: rifeplight <rifeplight@outlook.com>

rifeplight committed Nov 28, 2025 at 23:39 UTC 3f2cc50eb82e47167de3684d448910093eda4e91
18 files changed +92 -195
core/commands/files_test.go
+1 -3
@@ -1,7 +1,6 @@
1 package commands
2
3 import (
4 - "context"
4 "io"
5 "testing"
6
@@ -12,8 +11,7 @@ import (
11 )
12
13 func TestFilesCp_DagCborNodeFails(t *testing.T) {
15 - ctx, cancel := context.WithCancel(context.Background())
16 - defer cancel()
14 + ctx := t.Context()
15
16 cmdCtx, err := coremock.MockCmdsCtx()
17 require.NoError(t, err)
core/commands/get_test.go
+1 -3
@@ -1,7 +1,6 @@
1 package commands
2
3 import (
4 - "context"
4 "fmt"
5 "testing"
6
@@ -52,8 +51,7 @@ func TestGetOutputPath(t *testing.T) {
51
52 for i, tc := range cases {
53 t.Run(fmt.Sprintf("%s-%d", t.Name(), i), func(t *testing.T) {
55 - ctx, cancel := context.WithCancel(context.Background())
56 - defer cancel()
54 + ctx := t.Context()
55
56 req, err := cmds.NewRequest(ctx, []string{}, tc.opts, tc.args, nil, GetCmd)
57 if err != nil {
core/coreapi/test/path_test.go
+1 -2
@@ -15,8 +15,7 @@ import (
15 )
16
17 func TestPathUnixFSHAMTPartial(t *testing.T) {
18 - ctx, cancel := context.WithCancel(context.Background())
19 - defer cancel()
18 + ctx := t.Context()
19
20 // Create a node
21 apis, err := NodeProvider{}.MakeAPISwarm(t, ctx, true, true, 1)
core/coreiface/tests/block.go
+11 -23
@@ -2,7 +2,6 @@ package tests
2
3 import (
4 "bytes"
5 - "context"
5 "io"
6 "strings"
7 "testing"
@@ -55,8 +54,7 @@ func (tp *TestSuite) TestBlock(t *testing.T) {
54
55 // when no opts are passed, produced CID has 'raw' codec
56 func (tp *TestSuite) TestBlockPut(t *testing.T) {
58 - ctx, cancel := context.WithCancel(context.Background())
59 - defer cancel()
57 + ctx := t.Context()
58 api, err := tp.makeAPI(t, ctx)
59 if err != nil {
60 t.Fatal(err)
@@ -75,8 +73,7 @@ func (tp *TestSuite) TestBlockPut(t *testing.T) {
73 // Format is deprecated, it used invalid codec names.
74 // Confirm 'cbor' gets fixed to 'dag-cbor'
75 func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) {
78 - ctx, cancel := context.WithCancel(context.Background())
79 - defer cancel()
76 + ctx := t.Context()
77 api, err := tp.makeAPI(t, ctx)
78 if err != nil {
79 t.Fatal(err)
@@ -95,8 +92,7 @@ func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) {
92 // Format is deprecated, it used invalid codec names.
93 // Confirm 'protobuf' got fixed to 'dag-pb'
94 func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) {
98 - ctx, cancel := context.WithCancel(context.Background())
99 - defer cancel()
95 + ctx := t.Context()
96 api, err := tp.makeAPI(t, ctx)
97 if err != nil {
98 t.Fatal(err)
@@ -115,8 +111,7 @@ func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) {
111 // Format is deprecated, it used invalid codec names.
112 // Confirm fake codec 'v0' got fixed to CIDv0 (with implicit dag-pb codec)
113 func (tp *TestSuite) TestBlockPutFormatV0(t *testing.T) {
118 - ctx, cancel := context.WithCancel(context.Background())
119 - defer cancel()
114 + ctx := t.Context()
115 api, err := tp.makeAPI(t, ctx)
116 if err != nil {
117 t.Fatal(err)
@@ -133,8 +128,7 @@ func (tp *TestSuite) TestBlockPutFormatV0(t *testing.T) {
128 }
129
130 func (tp *TestSuite) TestBlockPutCidCodecDagCbor(t *testing.T) {
136 - ctx, cancel := context.WithCancel(context.Background())
137 - defer cancel()
131 + ctx := t.Context()
132 api, err := tp.makeAPI(t, ctx)
133 if err != nil {
134 t.Fatal(err)
@@ -151,8 +145,7 @@ func (tp *TestSuite) TestBlockPutCidCodecDagCbor(t *testing.T) {
145 }
146
147 func (tp *TestSuite) TestBlockPutCidCodecDagPb(t *testing.T) {
154 - ctx, cancel := context.WithCancel(context.Background())
155 - defer cancel()
148 + ctx := t.Context()
149 api, err := tp.makeAPI(t, ctx)
150 if err != nil {
151 t.Fatal(err)
@@ -169,8 +162,7 @@ func (tp *TestSuite) TestBlockPutCidCodecDagPb(t *testing.T) {
162 }
163
164 func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
172 - ctx, cancel := context.WithCancel(context.Background())
173 - defer cancel()
165 + ctx := t.Context()
166 api, err := tp.makeAPI(t, ctx)
167 if err != nil {
168 t.Fatal(err)
@@ -192,8 +184,7 @@ func (tp *TestSuite) TestBlockPutHash(t *testing.T) {
184 }
185
186 func (tp *TestSuite) TestBlockGet(t *testing.T) {
195 - ctx, cancel := context.WithCancel(context.Background())
196 - defer cancel()
187 + ctx := t.Context()
188 api, err := tp.makeAPI(t, ctx)
189 if err != nil {
190 t.Fatal(err)
@@ -230,8 +221,7 @@ func (tp *TestSuite) TestBlockGet(t *testing.T) {
221 }
222
223 func (tp *TestSuite) TestBlockRm(t *testing.T) {
233 - ctx, cancel := context.WithCancel(context.Background())
234 - defer cancel()
224 + ctx := t.Context()
225 api, err := tp.makeAPI(t, ctx)
226 if err != nil {
227 t.Fatal(err)
@@ -284,8 +274,7 @@ func (tp *TestSuite) TestBlockRm(t *testing.T) {
274 }
275
276 func (tp *TestSuite) TestBlockStat(t *testing.T) {
287 - ctx, cancel := context.WithCancel(context.Background())
288 - defer cancel()
277 + ctx := t.Context()
278 api, err := tp.makeAPI(t, ctx)
279 if err != nil {
280 t.Fatal(err)
@@ -311,8 +300,7 @@ func (tp *TestSuite) TestBlockStat(t *testing.T) {
300 }
301
302 func (tp *TestSuite) TestBlockPin(t *testing.T) {
314 - ctx, cancel := context.WithCancel(context.Background())
315 - defer cancel()
303 + ctx := t.Context()
304 api, err := tp.makeAPI(t, ctx)
305 if err != nil {
306 t.Fatal(err)
core/coreiface/tests/dag.go
+5 -11
@@ -1,7 +1,6 @@
1 package tests
2
3 import (
4 - "context"
4 "math"
5 "strings"
6 "testing"
@@ -38,8 +37,7 @@ var treeExpected = map[string]struct{}{
37 }
38
39 func (tp *TestSuite) TestPut(t *testing.T) {
41 - ctx, cancel := context.WithCancel(context.Background())
42 - defer cancel()
40 + ctx := t.Context()
41 api, err := tp.makeAPI(t, ctx)
42 if err != nil {
43 t.Fatal(err)
@@ -61,8 +59,7 @@ func (tp *TestSuite) TestPut(t *testing.T) {
59 }
60
61 func (tp *TestSuite) TestPutWithHash(t *testing.T) {
64 - ctx, cancel := context.WithCancel(context.Background())
65 - defer cancel()
62 + ctx := t.Context()
63 api, err := tp.makeAPI(t, ctx)
64 if err != nil {
65 t.Fatal(err)
@@ -84,8 +81,7 @@ func (tp *TestSuite) TestPutWithHash(t *testing.T) {
81 }
82
83 func (tp *TestSuite) TestDagPath(t *testing.T) {
87 - ctx, cancel := context.WithCancel(context.Background())
88 - defer cancel()
84 + ctx := t.Context()
85 api, err := tp.makeAPI(t, ctx)
86 if err != nil {
87 t.Fatal(err)
@@ -132,8 +128,7 @@ func (tp *TestSuite) TestDagPath(t *testing.T) {
128 }
129
130 func (tp *TestSuite) TestTree(t *testing.T) {
135 - ctx, cancel := context.WithCancel(context.Background())
136 - defer cancel()
131 + ctx := t.Context()
132 api, err := tp.makeAPI(t, ctx)
133 if err != nil {
134 t.Fatal(err)
@@ -167,8 +162,7 @@ func (tp *TestSuite) TestTree(t *testing.T) {
162 }
163
164 func (tp *TestSuite) TestBatch(t *testing.T) {
170 - ctx, cancel := context.WithCancel(context.Background())
171 - defer cancel()
165 + ctx := t.Context()
166 api, err := tp.makeAPI(t, ctx)
167 if err != nil {
168 t.Fatal(err)
core/coreiface/tests/key.go
+21 -43
@@ -1,7 +1,6 @@
1 package tests
2
3 import (
4 - "context"
4 "strings"
5 "testing"
6
@@ -43,8 +42,7 @@ func (tp *TestSuite) TestKey(t *testing.T) {
42 }
43
44 func (tp *TestSuite) TestListSelf(t *testing.T) {
46 - ctx, cancel := context.WithCancel(context.Background())
47 - defer cancel()
45 + ctx := t.Context()
46
47 api, err := tp.makeAPI(t, ctx)
48 require.NoError(t, err)
@@ -60,8 +58,7 @@ func (tp *TestSuite) TestListSelf(t *testing.T) {
58 }
59
60 func (tp *TestSuite) TestRenameSelf(t *testing.T) {
63 - ctx, cancel := context.WithCancel(context.Background())
64 - defer cancel()
61 + ctx := t.Context()
62
63 api, err := tp.makeAPI(t, ctx)
64 require.NoError(t, err)
@@ -74,8 +71,7 @@ func (tp *TestSuite) TestRenameSelf(t *testing.T) {
71 }
72
73 func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
77 - ctx, cancel := context.WithCancel(context.Background())
78 - defer cancel()
74 + ctx := t.Context()
75
76 api, err := tp.makeAPI(t, ctx)
77 require.NoError(t, err)
@@ -85,8 +81,7 @@ func (tp *TestSuite) TestRemoveSelf(t *testing.T) {
81 }
82
83 func (tp *TestSuite) TestGenerate(t *testing.T) {
88 - ctx, cancel := context.WithCancel(context.Background())
89 - defer cancel()
84 + ctx := t.Context()
85
86 api, err := tp.makeAPI(t, ctx)
87 require.NoError(t, err)
@@ -113,8 +108,7 @@ func verifyIPNSPath(t *testing.T, p string) {
108 }
109
110 func (tp *TestSuite) TestGenerateSize(t *testing.T) {
116 - ctx, cancel := context.WithCancel(context.Background())
117 - defer cancel()
111 + ctx := t.Context()
112
113 api, err := tp.makeAPI(t, ctx)
114 require.NoError(t, err)
@@ -129,8 +123,7 @@ func (tp *TestSuite) TestGenerateSize(t *testing.T) {
123 func (tp *TestSuite) TestGenerateType(t *testing.T) {
124 t.Skip("disabled until libp2p/specs#111 is fixed")
125
132 - ctx, cancel := context.WithCancel(context.Background())
133 - defer cancel()
126 + ctx := t.Context()
127
128 api, err := tp.makeAPI(t, ctx)
129 require.NoError(t, err)
@@ -143,8 +136,7 @@ func (tp *TestSuite) TestGenerateType(t *testing.T) {
136 }
137
138 func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
146 - ctx, cancel := context.WithCancel(context.Background())
147 - defer cancel()
139 + ctx := t.Context()
140
141 api, err := tp.makeAPI(t, ctx)
142 require.NoError(t, err)
@@ -160,8 +152,7 @@ func (tp *TestSuite) TestGenerateExisting(t *testing.T) {
152 }
153
154 func (tp *TestSuite) TestList(t *testing.T) {
163 - ctx, cancel := context.WithCancel(context.Background())
164 - defer cancel()
155 + ctx := t.Context()
156
157 api, err := tp.makeAPI(t, ctx)
158 require.NoError(t, err)
@@ -180,8 +171,7 @@ func (tp *TestSuite) TestList(t *testing.T) {
171 }
172
173 func (tp *TestSuite) TestRename(t *testing.T) {
183 - ctx, cancel := context.WithCancel(context.Background())
184 - defer cancel()
174 + ctx := t.Context()
175
176 api, err := tp.makeAPI(t, ctx)
177 require.NoError(t, err)
@@ -196,8 +186,7 @@ func (tp *TestSuite) TestRename(t *testing.T) {
186 }
187
188 func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
199 - ctx, cancel := context.WithCancel(context.Background())
200 - defer cancel()
189 + ctx := t.Context()
190
191 api, err := tp.makeAPI(t, ctx)
192 require.NoError(t, err)
@@ -210,8 +199,7 @@ func (tp *TestSuite) TestRenameToSelf(t *testing.T) {
199 }
200
201 func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
213 - ctx, cancel := context.WithCancel(context.Background())
214 - defer cancel()
202 + ctx := t.Context()
203
204 api, err := tp.makeAPI(t, ctx)
205 require.NoError(t, err)
@@ -224,8 +212,7 @@ func (tp *TestSuite) TestRenameToSelfForce(t *testing.T) {
212 }
213
214 func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
227 - ctx, cancel := context.WithCancel(context.Background())
228 - defer cancel()
215 + ctx := t.Context()
216
217 api, err := tp.makeAPI(t, ctx)
218 require.NoError(t, err)
@@ -241,8 +228,7 @@ func (tp *TestSuite) TestRenameOverwriteNoForce(t *testing.T) {
228 }
229
230 func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
244 - ctx, cancel := context.WithCancel(context.Background())
245 - defer cancel()
231 + ctx := t.Context()
232
233 api, err := tp.makeAPI(t, ctx)
234 require.NoError(t, err)
@@ -261,8 +247,7 @@ func (tp *TestSuite) TestRenameOverwrite(t *testing.T) {
247 }
248
249 func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
264 - ctx, cancel := context.WithCancel(context.Background())
265 - defer cancel()
250 + ctx := t.Context()
251
252 api, err := tp.makeAPI(t, ctx)
253 require.NoError(t, err)
@@ -277,8 +262,7 @@ func (tp *TestSuite) TestRenameSameNameNoForce(t *testing.T) {
262 }
263
264 func (tp *TestSuite) TestRenameSameName(t *testing.T) {
280 - ctx, cancel := context.WithCancel(context.Background())
281 - defer cancel()
265 + ctx := t.Context()
266
267 api, err := tp.makeAPI(t, ctx)
268 require.NoError(t, err)
@@ -293,8 +277,7 @@ func (tp *TestSuite) TestRenameSameName(t *testing.T) {
277 }
278
279 func (tp *TestSuite) TestRemove(t *testing.T) {
296 - ctx, cancel := context.WithCancel(context.Background())
297 - defer cancel()
280 + ctx := t.Context()
281
282 api, err := tp.makeAPI(t, ctx)
283 require.NoError(t, err)
@@ -317,8 +300,7 @@ func (tp *TestSuite) TestRemove(t *testing.T) {
300 }
301
302 func (tp *TestSuite) TestSign(t *testing.T) {
320 - ctx, cancel := context.WithCancel(context.Background())
321 - defer cancel()
303 + ctx := t.Context()
304
305 api, err := tp.makeAPI(t, ctx)
306 require.NoError(t, err)
@@ -348,8 +330,7 @@ func (tp *TestSuite) TestVerify(t *testing.T) {
330 t.Run("Verify Own Key", func(t *testing.T) {
331 t.Parallel()
332
351 - ctx, cancel := context.WithCancel(context.Background())
352 - defer cancel()
333 + ctx := t.Context()
334
335 api, err := tp.makeAPI(t, ctx)
336 require.NoError(t, err)
@@ -370,8 +351,7 @@ func (tp *TestSuite) TestVerify(t *testing.T) {
351 t.Run("Verify Self", func(t *testing.T) {
352 t.Parallel()
353
373 - ctx, cancel := context.WithCancel(context.Background())
374 - defer cancel()
354 + ctx := t.Context()
355
356 api, err := tp.makeAPIWithIdentityAndOffline(t, ctx)
357 require.NoError(t, err)
@@ -390,8 +370,7 @@ func (tp *TestSuite) TestVerify(t *testing.T) {
370 t.Parallel()
371
372 // Spin some node and get signature out.
393 - ctx, cancel := context.WithCancel(context.Background())
394 - defer cancel()
373 + ctx := t.Context()
374
375 api, err := tp.makeAPI(t, ctx)
376 require.NoError(t, err)
@@ -411,8 +390,7 @@ func (tp *TestSuite) TestVerify(t *testing.T) {
390 {"Prefixed IPNS Path", ipns.NameFromPeer(key.ID()).AsPath().String()},
391 } {
392 t.Run(testCase[0], func(t *testing.T) {
414 - ctx, cancel := context.WithCancel(context.Background())
415 - defer cancel()
393 + ctx := t.Context()
394
395 // Spin new node.
396 api, err := tp.makeAPI(t, ctx)
core/coreiface/tests/name.go
+3 -6
@@ -35,8 +35,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
35 }
36
37 func (tp *TestSuite) TestPublishResolve(t *testing.T) {
38 - ctx, cancel := context.WithCancel(context.Background())
39 - defer cancel()
38 + ctx := t.Context()
39 init := func() (coreiface.CoreAPI, path.Path) {
40 apis, err := tp.MakeAPISwarm(t, ctx, 5)
41 require.NoError(t, err)
@@ -120,8 +119,7 @@ func (tp *TestSuite) TestPublishResolve(t *testing.T) {
119 }
120
121 func (tp *TestSuite) TestBasicPublishResolveKey(t *testing.T) {
123 - ctx, cancel := context.WithCancel(context.Background())
124 - defer cancel()
122 + ctx := t.Context()
123 apis, err := tp.MakeAPISwarm(t, ctx, 5)
124 require.NoError(t, err)
125 api := apis[0]
@@ -142,8 +140,7 @@ func (tp *TestSuite) TestBasicPublishResolveKey(t *testing.T) {
140 }
141
142 func (tp *TestSuite) TestBasicPublishResolveTimeout(t *testing.T) {
145 - ctx, cancel := context.WithCancel(context.Background())
146 - defer cancel()
143 + ctx := t.Context()
144 apis, err := tp.MakeAPISwarm(t, ctx, 5)
145 require.NoError(t, err)
146 api := apis[0]
core/coreiface/tests/object.go
+4 -8
@@ -45,8 +45,7 @@ func putDagPbNode(t *testing.T, ctx context.Context, api iface.CoreAPI, data str
45 }
46
47 func (tp *TestSuite) TestObjectAddLink(t *testing.T) {
48 - ctx, cancel := context.WithCancel(context.Background())
49 - defer cancel()
48 + ctx := t.Context()
49 api, err := tp.makeAPI(t, ctx)
50 require.NoError(t, err)
51
@@ -72,8 +71,7 @@ func (tp *TestSuite) TestObjectAddLink(t *testing.T) {
71 }
72
73 func (tp *TestSuite) TestObjectAddLinkCreate(t *testing.T) {
75 - ctx, cancel := context.WithCancel(context.Background())
76 - defer cancel()
74 + ctx := t.Context()
75 api, err := tp.makeAPI(t, ctx)
76 require.NoError(t, err)
77
@@ -102,8 +100,7 @@ func (tp *TestSuite) TestObjectAddLinkCreate(t *testing.T) {
100 }
101
102 func (tp *TestSuite) TestObjectRmLink(t *testing.T) {
105 - ctx, cancel := context.WithCancel(context.Background())
106 - defer cancel()
103 + ctx := t.Context()
104 api, err := tp.makeAPI(t, ctx)
105 require.NoError(t, err)
106
@@ -127,8 +124,7 @@ func (tp *TestSuite) TestObjectRmLink(t *testing.T) {
124 }
125
126 func (tp *TestSuite) TestDiffTest(t *testing.T) {
130 - ctx, cancel := context.WithCancel(context.Background())
131 - defer cancel()
127 + ctx := t.Context()
128 api, err := tp.makeAPI(t, ctx)
129 require.NoError(t, err)
130
core/coreiface/tests/path.go
+5 -11
@@ -1,7 +1,6 @@
1 package tests
2
3 import (
4 - "context"
4 "fmt"
5 "math"
6 "strings"
@@ -32,8 +31,7 @@ func (tp *TestSuite) TestPath(t *testing.T) {
31 }
32
33 func (tp *TestSuite) TestMutablePath(t *testing.T) {
35 - ctx, cancel := context.WithCancel(context.Background())
36 - defer cancel()
34 + ctx := t.Context()
35
36 api, err := tp.makeAPI(t, ctx)
37 require.NoError(t, err)
@@ -49,8 +47,7 @@ func (tp *TestSuite) TestMutablePath(t *testing.T) {
47 }
48
49 func (tp *TestSuite) TestPathRemainder(t *testing.T) {
52 - ctx, cancel := context.WithCancel(context.Background())
53 - defer cancel()
50 + ctx := t.Context()
51
52 api, err := tp.makeAPI(t, ctx)
53 require.NoError(t, err)
@@ -71,8 +68,7 @@ func (tp *TestSuite) TestPathRemainder(t *testing.T) {
68 }
69
70 func (tp *TestSuite) TestEmptyPathRemainder(t *testing.T) {
74 - ctx, cancel := context.WithCancel(context.Background())
75 - defer cancel()
71 + ctx := t.Context()
72
73 api, err := tp.makeAPI(t, ctx)
74 require.NoError(t, err)
@@ -90,8 +86,7 @@ func (tp *TestSuite) TestEmptyPathRemainder(t *testing.T) {
86 }
87
88 func (tp *TestSuite) TestInvalidPathRemainder(t *testing.T) {
93 - ctx, cancel := context.WithCancel(context.Background())
94 - defer cancel()
89 + ctx := t.Context()
90
91 api, err := tp.makeAPI(t, ctx)
92 require.NoError(t, err)
@@ -112,8 +107,7 @@ func (tp *TestSuite) TestInvalidPathRemainder(t *testing.T) {
107 }
108
109 func (tp *TestSuite) TestPathRoot(t *testing.T) {
115 - ctx, cancel := context.WithCancel(context.Background())
116 - defer cancel()
110 + ctx := t.Context()
111
112 api, err := tp.makeAPI(t, ctx)
113 require.NoError(t, err)
core/coreiface/tests/pin.go
+9 -18
@@ -33,8 +33,7 @@ func (tp *TestSuite) TestPin(t *testing.T) {
33 }
34
35 func (tp *TestSuite) TestPinAdd(t *testing.T) {
36 - ctx, cancel := context.WithCancel(context.Background())
37 - defer cancel()
36 + ctx := t.Context()
37 api, err := tp.makeAPI(t, ctx)
38 if err != nil {
39 t.Fatal(err)
@@ -52,8 +51,7 @@ func (tp *TestSuite) TestPinAdd(t *testing.T) {
51 }
52
53 func (tp *TestSuite) TestPinSimple(t *testing.T) {
55 - ctx, cancel := context.WithCancel(context.Background())
56 - defer cancel()
54 + ctx := t.Context()
55 api, err := tp.makeAPI(t, ctx)
56 if err != nil {
57 t.Fatal(err)
@@ -104,8 +102,7 @@ func (tp *TestSuite) TestPinSimple(t *testing.T) {
102 }
103
104 func (tp *TestSuite) TestPinRecursive(t *testing.T) {
107 - ctx, cancel := context.WithCancel(context.Background())
108 - defer cancel()
105 + ctx := t.Context()
106 api, err := tp.makeAPI(t, ctx)
107 if err != nil {
108 t.Fatal(err)
@@ -251,8 +248,7 @@ func (tp *TestSuite) TestPinRecursive(t *testing.T) {
248
249 // TestPinLsIndirect verifies that indirect nodes are listed by pin ls even if a parent node is directly pinned
250 func (tp *TestSuite) TestPinLsIndirect(t *testing.T) {
254 - ctx, cancel := context.WithCancel(context.Background())
255 - defer cancel()
251 + ctx := t.Context()
252 api, err := tp.makeAPI(t, ctx)
253 if err != nil {
254 t.Fatal(err)
@@ -284,8 +280,7 @@ func (tp *TestSuite) TestPinLsPrecedence(t *testing.T) {
280 }
281
282 func (tp *TestSuite) TestPinLsPredenceRecursiveIndirect(t *testing.T) {
287 - ctx, cancel := context.WithCancel(context.Background())
288 - defer cancel()
283 + ctx := t.Context()
284 api, err := tp.makeAPI(t, ctx)
285 if err != nil {
286 t.Fatal(err)
@@ -308,8 +303,7 @@ func (tp *TestSuite) TestPinLsPredenceRecursiveIndirect(t *testing.T) {
303 }
304
305 func (tp *TestSuite) TestPinLsPrecedenceDirectIndirect(t *testing.T) {
311 - ctx, cancel := context.WithCancel(context.Background())
312 - defer cancel()
306 + ctx := t.Context()
307 api, err := tp.makeAPI(t, ctx)
308 if err != nil {
309 t.Fatal(err)
@@ -332,8 +326,7 @@ func (tp *TestSuite) TestPinLsPrecedenceDirectIndirect(t *testing.T) {
326 }
327
328 func (tp *TestSuite) TestPinLsPrecedenceRecursiveDirect(t *testing.T) {
335 - ctx, cancel := context.WithCancel(context.Background())
336 - defer cancel()
329 + ctx := t.Context()
330 api, err := tp.makeAPI(t, ctx)
331 if err != nil {
332 t.Fatal(err)
@@ -368,8 +361,7 @@ func (tp *TestSuite) TestPinLsPrecedenceRecursiveDirect(t *testing.T) {
361 }
362
363 func (tp *TestSuite) TestPinIsPinned(t *testing.T) {
371 - ctx, cancel := context.WithCancel(context.Background())
372 - defer cancel()
364 + ctx := t.Context()
365 api, err := tp.makeAPI(t, ctx)
366 if err != nil {
367 t.Fatal(err)
@@ -583,8 +575,7 @@ func assertIsPinned(t *testing.T, ctx context.Context, api iface.CoreAPI, p path
575 }
576
577 func (tp *TestSuite) TestPinNames(t *testing.T) {
586 - ctx, cancel := context.WithCancel(context.Background())
587 - defer cancel()
578 + ctx := t.Context()
579 api, err := tp.makeAPI(t, ctx)
580 require.NoError(t, err)
581
core/coreiface/tests/routing.go
+6 -12
@@ -41,8 +41,7 @@ func (tp *TestSuite) testRoutingPublishKey(t *testing.T, ctx context.Context, ap
41 }
42
43 func (tp *TestSuite) TestRoutingGet(t *testing.T) {
44 - ctx, cancel := context.WithCancel(context.Background())
45 - defer cancel()
44 + ctx := t.Context()
45
46 apis, err := tp.MakeAPISwarm(t, ctx, 2)
47 require.NoError(t, err)
@@ -63,8 +62,7 @@ func (tp *TestSuite) TestRoutingGet(t *testing.T) {
62 }
63
64 func (tp *TestSuite) TestRoutingPut(t *testing.T) {
66 - ctx, cancel := context.WithCancel(context.Background())
67 - defer cancel()
65 + ctx := t.Context()
66 apis, err := tp.MakeAPISwarm(t, ctx, 2)
67 require.NoError(t, err)
68
@@ -81,8 +79,7 @@ func (tp *TestSuite) TestRoutingPut(t *testing.T) {
79 }
80
81 func (tp *TestSuite) TestRoutingPutOffline(t *testing.T) {
84 - ctx, cancel := context.WithCancel(context.Background())
85 - defer cancel()
82 + ctx := t.Context()
83
84 // init a swarm & publish an IPNS entry to get a valid payload
85 apis, err := tp.MakeAPISwarm(t, ctx, 2)
@@ -104,8 +101,7 @@ func (tp *TestSuite) TestRoutingPutOffline(t *testing.T) {
101 }
102
103 func (tp *TestSuite) TestRoutingFindPeer(t *testing.T) {
107 - ctx, cancel := context.WithCancel(context.Background())
108 - defer cancel()
104 + ctx := t.Context()
105 apis, err := tp.MakeAPISwarm(t, ctx, 5)
106 if err != nil {
107 t.Fatal(err)
@@ -159,8 +155,7 @@ func (tp *TestSuite) TestRoutingFindPeer(t *testing.T) {
155 }
156
157 func (tp *TestSuite) TestRoutingFindProviders(t *testing.T) {
162 - ctx, cancel := context.WithCancel(context.Background())
163 - defer cancel()
158 + ctx := t.Context()
159 apis, err := tp.MakeAPISwarm(t, ctx, 5)
160 if err != nil {
161 t.Fatal(err)
@@ -198,8 +193,7 @@ func (tp *TestSuite) TestRoutingFindProviders(t *testing.T) {
193 }
194
195 func (tp *TestSuite) TestRoutingProvide(t *testing.T) {
201 - ctx, cancel := context.WithCancel(context.Background())
202 - defer cancel()
196 + ctx := t.Context()
197 apis, err := tp.MakeAPISwarm(t, ctx, 5)
198 if err != nil {
199 t.Fatal(err)
core/coreiface/tests/unixfs.go
+12 -24
@@ -98,8 +98,7 @@ func wrapped(names ...string) func(f files.Node) files.Node {
98 }
99
100 func (tp *TestSuite) TestAdd(t *testing.T) {
101 - ctx, cancel := context.WithCancel(context.Background())
102 - defer cancel()
101 + ctx := t.Context()
102 api, err := tp.makeAPI(t, ctx)
103 if err != nil {
104 t.Fatal(err)
@@ -532,8 +531,7 @@ func (tp *TestSuite) TestAdd(t *testing.T) {
531 }
532
533 func (tp *TestSuite) TestAddPinned(t *testing.T) {
535 - ctx, cancel := context.WithCancel(context.Background())
536 - defer cancel()
534 + ctx := t.Context()
535 api, err := tp.makeAPI(t, ctx)
536 if err != nil {
537 t.Fatal(err)
@@ -558,8 +556,7 @@ func (tp *TestSuite) TestAddPinned(t *testing.T) {
556 }
557
558 func (tp *TestSuite) TestAddHashOnly(t *testing.T) {
561 - ctx, cancel := context.WithCancel(context.Background())
562 - defer cancel()
559 + ctx := t.Context()
560 api, err := tp.makeAPI(t, ctx)
561 if err != nil {
562 t.Fatal(err)
@@ -584,8 +581,7 @@ func (tp *TestSuite) TestAddHashOnly(t *testing.T) {
581 }
582
583 func (tp *TestSuite) TestGetEmptyFile(t *testing.T) {
587 - ctx, cancel := context.WithCancel(context.Background())
588 - defer cancel()
584 + ctx := t.Context()
585 api, err := tp.makeAPI(t, ctx)
586 if err != nil {
587 t.Fatal(err)
@@ -617,8 +613,7 @@ func (tp *TestSuite) TestGetEmptyFile(t *testing.T) {
613 }
614
615 func (tp *TestSuite) TestGetDir(t *testing.T) {
620 - ctx, cancel := context.WithCancel(context.Background())
621 - defer cancel()
616 + ctx := t.Context()
617 api, err := tp.makeAPI(t, ctx)
618 if err != nil {
619 t.Fatal(err)
@@ -645,8 +640,7 @@ func (tp *TestSuite) TestGetDir(t *testing.T) {
640 }
641
642 func (tp *TestSuite) TestGetNonUnixfs(t *testing.T) {
648 - ctx, cancel := context.WithCancel(context.Background())
649 - defer cancel()
643 + ctx := t.Context()
644 api, err := tp.makeAPI(t, ctx)
645 if err != nil {
646 t.Fatal(err)
@@ -665,8 +659,7 @@ func (tp *TestSuite) TestGetNonUnixfs(t *testing.T) {
659 }
660
661 func (tp *TestSuite) TestLs(t *testing.T) {
668 - ctx, cancel := context.WithCancel(context.Background())
669 - defer cancel()
662 + ctx := t.Context()
663 api, err := tp.makeAPI(t, ctx)
664 if err != nil {
665 t.Fatal(err)
@@ -769,8 +762,7 @@ func (tp *TestSuite) TestEntriesExpired(t *testing.T) {
762 }
763
764 func (tp *TestSuite) TestLsEmptyDir(t *testing.T) {
772 - ctx, cancel := context.WithCancel(context.Background())
773 - defer cancel()
765 + ctx := t.Context()
766 api, err := tp.makeAPI(t, ctx)
767 if err != nil {
768 t.Fatal(err)
@@ -802,8 +794,7 @@ func (tp *TestSuite) TestLsEmptyDir(t *testing.T) {
794
795 // TODO(lgierth) this should test properly, with len(links) > 0
796 func (tp *TestSuite) TestLsNonUnixfs(t *testing.T) {
805 - ctx, cancel := context.WithCancel(context.Background())
806 - defer cancel()
797 + ctx := t.Context()
798 api, err := tp.makeAPI(t, ctx)
799 if err != nil {
800 t.Fatal(err)
@@ -870,8 +861,7 @@ func (f *closeTestF) Close() error {
861 }
862
863 func (tp *TestSuite) TestAddCloses(t *testing.T) {
873 - ctx, cancel := context.WithCancel(context.Background())
874 - defer cancel()
864 + ctx := t.Context()
865 api, err := tp.makeAPI(t, ctx)
866 if err != nil {
867 t.Fatal(err)
@@ -908,8 +898,7 @@ func (tp *TestSuite) TestAddCloses(t *testing.T) {
898 }
899
900 func (tp *TestSuite) TestGetSeek(t *testing.T) {
911 - ctx, cancel := context.WithCancel(context.Background())
912 - defer cancel()
901 + ctx := t.Context()
902 api, err := tp.makeAPI(t, ctx)
903 if err != nil {
904 t.Fatal(err)
@@ -1014,8 +1003,7 @@ func (tp *TestSuite) TestGetSeek(t *testing.T) {
1003 }
1004
1005 func (tp *TestSuite) TestGetReadAt(t *testing.T) {
1017 - ctx, cancel := context.WithCancel(context.Background())
1018 - defer cancel()
1006 + ctx := t.Context()
1007 api, err := tp.makeAPI(t, ctx)
1008 if err != nil {
1009 t.Fatal(err)
core/node/libp2p/rcmgr_logging_test.go
+1 -3
@@ -1,7 +1,6 @@
1 package libp2p
2
3 import (
4 - "context"
4 "testing"
5 "time"
6
@@ -42,8 +41,7 @@ func TestLoggingResourceManager(t *testing.T) {
41 }
42
43 // run the logger which will write an entry for those errors
45 - ctx, cancel := context.WithCancel(context.Background())
46 - defer cancel()
44 + ctx := t.Context()
45 lrm.start(ctx)
46 clock.Add(3 * time.Second)
47
repo/fsrepo/migrations/fetch_test.go
+3 -7
@@ -3,7 +3,6 @@ package migrations
3 import (
4 "bufio"
5 "bytes"
6 - "context"
6 "fmt"
7 "os"
8 "path/filepath"
@@ -42,8 +41,7 @@ func TestGetDistPath(t *testing.T) {
41 }
42
43 func TestHttpFetch(t *testing.T) {
45 - ctx, cancel := context.WithCancel(context.Background())
46 - defer cancel()
44 + ctx := t.Context()
45
46 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
47
@@ -79,8 +77,7 @@ func TestHttpFetch(t *testing.T) {
77 func TestFetchBinary(t *testing.T) {
78 tmpDir := t.TempDir()
79
82 - ctx, cancel := context.WithCancel(context.Background())
83 - defer cancel()
80 + ctx := t.Context()
81
82 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
83
@@ -162,8 +159,7 @@ func TestFetchBinary(t *testing.T) {
159 }
160
161 func TestMultiFetcher(t *testing.T) {
165 - ctx, cancel := context.WithCancel(context.Background())
166 - defer cancel()
162 + ctx := t.Context()
163
164 badFetcher := NewHttpFetcher("", "bad-url", "", 0)
165 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher_test.go
+2 -5
@@ -3,7 +3,6 @@ package ipfsfetcher
3 import (
4 "bufio"
5 "bytes"
6 - "context"
6 "fmt"
7 "os"
8 "path/filepath"
@@ -23,8 +22,7 @@ func init() {
22 func TestIpfsFetcher(t *testing.T) {
23 skipUnlessEpic(t)
24
26 - ctx, cancel := context.WithCancel(context.Background())
27 - defer cancel()
25 + ctx := t.Context()
26
27 fetcher := NewIpfsFetcher("", 0, nil, "")
28 defer fetcher.Close()
@@ -58,8 +56,7 @@ func TestIpfsFetcher(t *testing.T) {
56 }
57
58 func TestInitIpfsFetcher(t *testing.T) {
61 - ctx, cancel := context.WithCancel(context.Background())
62 - defer cancel()
59 + ctx := t.Context()
60
61 f := NewIpfsFetcher("", 0, nil, "")
62 defer f.Close()
repo/fsrepo/migrations/migrations_test.go
+4 -8
@@ -15,8 +15,7 @@ import (
15 func TestFindMigrations(t *testing.T) {
16 tmpDir := t.TempDir()
17
18 - ctx, cancel := context.WithCancel(context.Background())
19 - defer cancel()
18 + ctx := t.Context()
19
20 migs, bins, err := findMigrations(ctx, 0, 5)
21 if err != nil {
@@ -60,8 +59,7 @@ func TestFindMigrations(t *testing.T) {
59 func TestFindMigrationsReverse(t *testing.T) {
60 tmpDir := t.TempDir()
61
63 - ctx, cancel := context.WithCancel(context.Background())
64 - defer cancel()
62 + ctx := t.Context()
63
64 migs, bins, err := findMigrations(ctx, 5, 0)
65 if err != nil {
@@ -103,8 +101,7 @@ func TestFindMigrationsReverse(t *testing.T) {
101 }
102
103 func TestFetchMigrations(t *testing.T) {
106 - ctx, cancel := context.WithCancel(context.Background())
107 - defer cancel()
104 + ctx := t.Context()
105
106 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
107
@@ -156,8 +153,7 @@ func TestRunMigrations(t *testing.T) {
153
154 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
155
159 - ctx, cancel := context.WithCancel(context.Background())
160 - defer cancel()
156 + ctx := t.Context()
157
158 targetVer := 9
159
repo/fsrepo/migrations/versions_test.go
+2 -5
@@ -1,7 +1,6 @@
1 package migrations
2
3 import (
4 - "context"
4 "testing"
5
6 "github.com/blang/semver/v4"
@@ -10,8 +9,7 @@ import (
9 const testDist = "go-ipfs"
10
11 func TestDistVersions(t *testing.T) {
13 - ctx, cancel := context.WithCancel(context.Background())
14 - defer cancel()
12 + ctx := t.Context()
13
14 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
15
@@ -27,8 +25,7 @@ func TestDistVersions(t *testing.T) {
25 }
26
27 func TestLatestDistVersion(t *testing.T) {
30 - ctx, cancel := context.WithCancel(context.Background())
31 - defer cancel()
28 + ctx := t.Context()
29
30 fetcher := NewHttpFetcher(testIpfsDist, testServer.URL, "", 0)
31
test/integration/bitswap_wo_routing_test.go
+1 -3
@@ -2,7 +2,6 @@ package integrationtest
2
3 import (
4 "bytes"
5 - "context"
5 "testing"
6
7 blocks "github.com/ipfs/go-block-format"
@@ -14,8 +13,7 @@ import (
13 )
14
15 func TestBitswapWithoutRouting(t *testing.T) {
17 - ctx, cancel := context.WithCancel(context.Background())
18 - defer cancel()
16 + ctx := t.Context()
17 const numPeers = 4
18
19 // create network