@cryptotaxi247 / kubo / commits / e5a2d8e6f

coreapi: make sure to cancel context in tests

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@aa64f771136226accbcae0213eb929ff79697046 This commit was moved from ipfs/boxo@23069a4c459b67e966fa5370e980aaab410e718b

Łukasz Magiera committed Dec 20, 2018 at 22:27 UTC e5a2d8e6f6ac387985f52ccb9eaf3172dc5b88ee
10 files changed +165 -66
core/coreiface/tests/api.go
+36 -1
@@ -3,6 +3,7 @@ package tests
3 import (
4 "context"
5 "testing"
6 + "time"
7
8 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
9 )
@@ -21,12 +22,37 @@ type Provider interface {
22 MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error)
23 }
24
25 +func (tp *provider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) {
26 + tp.apis <- 1
27 + go func() {
28 + <-ctx.Done()
29 + tp.apis <- -1
30 + }()
31 +
32 + return tp.Provider.MakeAPISwarm(ctx, fullIdentity, n)
33 +}
34 +
35 type provider struct {
36 Provider
37 +
38 + apis chan int
39 }
40
41 func TestApi(p Provider) func(t *testing.T) {
29 - tp := &provider{p}
42 + running := 1
43 + apis := make(chan int)
44 + zeroRunning := make(chan struct{})
45 + go func() {
46 + for i := range apis {
47 + running += i
48 + if running < 1 {
49 + close(zeroRunning)
50 + return
51 + }
52 + }
53 + }()
54 +
55 + tp := &provider{Provider: p, apis: apis}
56
57 return func(t *testing.T) {
58 t.Run("Block", tp.TestBlock)
@@ -39,5 +65,14 @@ func TestApi(p Provider) func(t *testing.T) {
65 t.Run("Pin", tp.TestPin)
66 t.Run("PubSub", tp.TestPubSub)
67 t.Run("Unixfs", tp.TestUnixfs)
68 +
69 + apis <- -1
70 + t.Run("TestsCancelCtx", func(t *testing.T) {
71 + select {
72 + case <-zeroRunning:
73 + case <-time.After(time.Second):
74 + t.Errorf("%d node(s) not closed", running)
75 + }
76 + })
77 }
78 }
core/coreiface/tests/block.go
+12 -6
@@ -22,7 +22,8 @@ func (tp *provider) TestBlock(t *testing.T) {
22 }
23
24 func (tp *provider) TestBlockPut(t *testing.T) {
25 - ctx := context.Background()
25 + ctx, cancel := context.WithCancel(context.Background())
26 + defer cancel()
27 api, err := tp.makeAPI(ctx)
28 if err != nil {
29 t.Error(err)
@@ -39,7 +40,8 @@ func (tp *provider) TestBlockPut(t *testing.T) {
40 }
41
42 func (tp *provider) TestBlockPutFormat(t *testing.T) {
42 - ctx := context.Background()
43 + ctx, cancel := context.WithCancel(context.Background())
44 + defer cancel()
45 api, err := tp.makeAPI(ctx)
46 if err != nil {
47 t.Error(err)
@@ -56,7 +58,8 @@ func (tp *provider) TestBlockPutFormat(t *testing.T) {
58 }
59
60 func (tp *provider) TestBlockPutHash(t *testing.T) {
59 - ctx := context.Background()
61 + ctx, cancel := context.WithCancel(context.Background())
62 + defer cancel()
63 api, err := tp.makeAPI(ctx)
64 if err != nil {
65 t.Error(err)
@@ -73,7 +76,8 @@ func (tp *provider) TestBlockPutHash(t *testing.T) {
76 }
77
78 func (tp *provider) TestBlockGet(t *testing.T) {
76 - ctx := context.Background()
79 + ctx, cancel := context.WithCancel(context.Background())
80 + defer cancel()
81 api, err := tp.makeAPI(ctx)
82 if err != nil {
83 t.Error(err)
@@ -113,7 +117,8 @@ func (tp *provider) TestBlockGet(t *testing.T) {
117 }
118
119 func (tp *provider) TestBlockRm(t *testing.T) {
116 - ctx := context.Background()
120 + ctx, cancel := context.WithCancel(context.Background())
121 + defer cancel()
122 api, err := tp.makeAPI(ctx)
123 if err != nil {
124 t.Error(err)
@@ -166,7 +171,8 @@ func (tp *provider) TestBlockRm(t *testing.T) {
171 }
172
173 func (tp *provider) TestBlockStat(t *testing.T) {
169 - ctx := context.Background()
174 + ctx, cancel := context.WithCancel(context.Background())
175 + defer cancel()
176 api, err := tp.makeAPI(ctx)
177 if err != nil {
178 t.Error(err)
core/coreiface/tests/dag.go
+10 -5
@@ -31,7 +31,8 @@ var (
31 )
32
33 func (tp *provider) TestPut(t *testing.T) {
34 - ctx := context.Background()
34 + ctx, cancel := context.WithCancel(context.Background())
35 + defer cancel()
36 api, err := tp.makeAPI(ctx)
37 if err != nil {
38 t.Error(err)
@@ -48,7 +49,8 @@ func (tp *provider) TestPut(t *testing.T) {
49 }
50
51 func (tp *provider) TestPutWithHash(t *testing.T) {
51 - ctx := context.Background()
52 + ctx, cancel := context.WithCancel(context.Background())
53 + defer cancel()
54 api, err := tp.makeAPI(ctx)
55 if err != nil {
56 t.Error(err)
@@ -65,7 +67,8 @@ func (tp *provider) TestPutWithHash(t *testing.T) {
67 }
68
69 func (tp *provider) TestDagPath(t *testing.T) {
68 - ctx := context.Background()
70 + ctx, cancel := context.WithCancel(context.Background())
71 + defer cancel()
72 api, err := tp.makeAPI(ctx)
73 if err != nil {
74 t.Error(err)
@@ -97,7 +100,8 @@ func (tp *provider) TestDagPath(t *testing.T) {
100 }
101
102 func (tp *provider) TestTree(t *testing.T) {
100 - ctx := context.Background()
103 + ctx, cancel := context.WithCancel(context.Background())
104 + defer cancel()
105 api, err := tp.makeAPI(ctx)
106 if err != nil {
107 t.Error(err)
@@ -126,7 +130,8 @@ func (tp *provider) TestTree(t *testing.T) {
130 }
131
132 func (tp *provider) TestBatch(t *testing.T) {
129 - ctx := context.Background()
133 + ctx, cancel := context.WithCancel(context.Background())
134 + defer cancel()
135 api, err := tp.makeAPI(ctx)
136 if err != nil {
137 t.Error(err)
core/coreiface/tests/dht.go
+6 -3
@@ -15,7 +15,8 @@ func (tp *provider) TestDht(t *testing.T) {
15 }
16
17 func (tp *provider) TestDhtFindPeer(t *testing.T) {
18 - ctx := context.Background()
18 + ctx, cancel := context.WithCancel(context.Background())
19 + defer cancel()
20 apis, err := tp.MakeAPISwarm(ctx, true, 5)
21 if err != nil {
22 t.Fatal(err)
@@ -51,7 +52,8 @@ func (tp *provider) TestDhtFindPeer(t *testing.T) {
52 }
53
54 func (tp *provider) TestDhtFindProviders(t *testing.T) {
54 - ctx := context.Background()
55 + ctx, cancel := context.WithCancel(context.Background())
56 + defer cancel()
57 apis, err := tp.MakeAPISwarm(ctx, true, 5)
58 if err != nil {
59 t.Fatal(err)
@@ -80,7 +82,8 @@ func (tp *provider) TestDhtFindProviders(t *testing.T) {
82 }
83
84 func (tp *provider) TestDhtProvide(t *testing.T) {
83 - ctx := context.Background()
85 + ctx, cancel := context.WithCancel(context.Background())
86 + defer cancel()
87 apis, err := tp.MakeAPISwarm(ctx, true, 5)
88 if err != nil {
89 t.Fatal(err)
core/coreiface/tests/key.go
+32 -16
@@ -28,7 +28,8 @@ func (tp *provider) TestKey(t *testing.T) {
28 }
29
30 func (tp *provider) TestListSelf(t *testing.T) {
31 - ctx := context.Background()
31 + ctx, cancel := context.WithCancel(context.Background())
32 + defer cancel()
33 api, err := tp.makeAPI(ctx)
34 if err != nil {
35 t.Fatal(err)
@@ -61,7 +62,8 @@ func (tp *provider) TestListSelf(t *testing.T) {
62 }
63
64 func (tp *provider) TestRenameSelf(t *testing.T) {
64 - ctx := context.Background()
65 + ctx, cancel := context.WithCancel(context.Background())
66 + defer cancel()
67 api, err := tp.makeAPI(ctx)
68 if err != nil {
69 t.Fatal(err)
@@ -88,7 +90,8 @@ func (tp *provider) TestRenameSelf(t *testing.T) {
90 }
91
92 func (tp *provider) TestRemoveSelf(t *testing.T) {
91 - ctx := context.Background()
93 + ctx, cancel := context.WithCancel(context.Background())
94 + defer cancel()
95 api, err := tp.makeAPI(ctx)
96 if err != nil {
97 t.Fatal(err)
@@ -106,7 +109,8 @@ func (tp *provider) TestRemoveSelf(t *testing.T) {
109 }
110
111 func (tp *provider) TestGenerate(t *testing.T) {
109 - ctx := context.Background()
112 + ctx, cancel := context.WithCancel(context.Background())
113 + defer cancel()
114 api, err := tp.makeAPI(ctx)
115 if err != nil {
116 t.Error(err)
@@ -128,7 +132,8 @@ func (tp *provider) TestGenerate(t *testing.T) {
132 }
133
134 func (tp *provider) TestGenerateSize(t *testing.T) {
131 - ctx := context.Background()
135 + ctx, cancel := context.WithCancel(context.Background())
136 + defer cancel()
137 api, err := tp.makeAPI(ctx)
138 if err != nil {
139 t.Error(err)
@@ -150,7 +155,8 @@ func (tp *provider) TestGenerateSize(t *testing.T) {
155 }
156
157 func (tp *provider) TestGenerateType(t *testing.T) {
153 - ctx := context.Background()
158 + ctx, cancel := context.WithCancel(context.Background())
159 + defer cancel()
160 t.Skip("disabled until libp2p/specs#111 is fixed")
161
162 api, err := tp.makeAPI(ctx)
@@ -175,7 +181,8 @@ func (tp *provider) TestGenerateType(t *testing.T) {
181 }
182
183 func (tp *provider) TestGenerateExisting(t *testing.T) {
178 - ctx := context.Background()
184 + ctx, cancel := context.WithCancel(context.Background())
185 + defer cancel()
186 api, err := tp.makeAPI(ctx)
187 if err != nil {
188 t.Error(err)
@@ -207,7 +214,8 @@ func (tp *provider) TestGenerateExisting(t *testing.T) {
214 }
215
216 func (tp *provider) TestList(t *testing.T) {
210 - ctx := context.Background()
217 + ctx, cancel := context.WithCancel(context.Background())
218 + defer cancel()
219 api, err := tp.makeAPI(ctx)
220 if err != nil {
221 t.Error(err)
@@ -252,7 +260,8 @@ func (tp *provider) TestList(t *testing.T) {
260 }
261
262 func (tp *provider) TestRename(t *testing.T) {
255 - ctx := context.Background()
263 + ctx, cancel := context.WithCancel(context.Background())
264 + defer cancel()
265 api, err := tp.makeAPI(ctx)
266 if err != nil {
267 t.Error(err)
@@ -280,7 +289,8 @@ func (tp *provider) TestRename(t *testing.T) {
289 }
290
291 func (tp *provider) TestRenameToSelf(t *testing.T) {
283 - ctx := context.Background()
292 + ctx, cancel := context.WithCancel(context.Background())
293 + defer cancel()
294 api, err := tp.makeAPI(ctx)
295 if err != nil {
296 t.Error(err)
@@ -303,7 +313,8 @@ func (tp *provider) TestRenameToSelf(t *testing.T) {
313 }
314
315 func (tp *provider) TestRenameToSelfForce(t *testing.T) {
306 - ctx := context.Background()
316 + ctx, cancel := context.WithCancel(context.Background())
317 + defer cancel()
318 api, err := tp.makeAPI(ctx)
319 if err != nil {
320 t.Error(err)
@@ -326,7 +337,8 @@ func (tp *provider) TestRenameToSelfForce(t *testing.T) {
337 }
338
339 func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
329 - ctx := context.Background()
340 + ctx, cancel := context.WithCancel(context.Background())
341 + defer cancel()
342 api, err := tp.makeAPI(ctx)
343 if err != nil {
344 t.Error(err)
@@ -355,7 +367,8 @@ func (tp *provider) TestRenameOverwriteNoForce(t *testing.T) {
367 }
368
369 func (tp *provider) TestRenameOverwrite(t *testing.T) {
358 - ctx := context.Background()
370 + ctx, cancel := context.WithCancel(context.Background())
371 + defer cancel()
372 api, err := tp.makeAPI(ctx)
373 if err != nil {
374 t.Error(err)
@@ -393,7 +406,8 @@ func (tp *provider) TestRenameOverwrite(t *testing.T) {
406 }
407
408 func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
396 - ctx := context.Background()
409 + ctx, cancel := context.WithCancel(context.Background())
410 + defer cancel()
411 api, err := tp.makeAPI(ctx)
412 if err != nil {
413 t.Error(err)
@@ -421,7 +435,8 @@ func (tp *provider) TestRenameSameNameNoForce(t *testing.T) {
435 }
436
437 func (tp *provider) TestRenameSameName(t *testing.T) {
424 - ctx := context.Background()
438 + ctx, cancel := context.WithCancel(context.Background())
439 + defer cancel()
440 api, err := tp.makeAPI(ctx)
441 if err != nil {
442 t.Error(err)
@@ -449,7 +464,8 @@ func (tp *provider) TestRenameSameName(t *testing.T) {
464 }
465
466 func (tp *provider) TestRemove(t *testing.T) {
452 - ctx := context.Background()
467 + ctx, cancel := context.WithCancel(context.Background())
468 + defer cancel()
469 api, err := tp.makeAPI(ctx)
470 if err != nil {
471 t.Error(err)
core/coreiface/tests/name.go
+6 -3
@@ -36,7 +36,8 @@ func appendPath(p coreiface.Path, sub string) coreiface.Path {
36 }
37
38 func (tp *provider) TestPublishResolve(t *testing.T) {
39 - ctx := context.Background()
39 + ctx, cancel := context.WithCancel(context.Background())
40 + defer cancel()
41 init := func() (coreiface.CoreAPI, coreiface.Path) {
42 apis, err := tp.MakeAPISwarm(ctx, true, 5)
43 if err != nil {
@@ -185,7 +186,8 @@ func (tp *provider) TestPublishResolve(t *testing.T) {
186 }
187
188 func (tp *provider) TestBasicPublishResolveKey(t *testing.T) {
188 - ctx := context.Background()
189 + ctx, cancel := context.WithCancel(context.Background())
190 + defer cancel()
191 apis, err := tp.MakeAPISwarm(ctx, true, 5)
192 if err != nil {
193 t.Fatal(err)
@@ -228,7 +230,8 @@ func (tp *provider) TestBasicPublishResolveKey(t *testing.T) {
230 func (tp *provider) TestBasicPublishResolveTimeout(t *testing.T) {
231 t.Skip("ValidTime doesn't appear to work at this time resolution")
232
231 - ctx := context.Background()
233 + ctx, cancel := context.WithCancel(context.Background())
234 + defer cancel()
235 apis, err := tp.MakeAPISwarm(ctx, true, 5)
236 if err != nil {
237 t.Fatal(err)
core/coreiface/tests/object.go
+24 -12
@@ -28,7 +28,8 @@ func (tp *provider) TestObject(t *testing.T) {
28 }
29
30 func (tp *provider) TestNew(t *testing.T) {
31 - ctx := context.Background()
31 + ctx, cancel := context.WithCancel(context.Background())
32 + defer cancel()
33 api, err := tp.makeAPI(ctx)
34 if err != nil {
35 t.Fatal(err)
@@ -54,7 +55,8 @@ func (tp *provider) TestNew(t *testing.T) {
55 }
56
57 func (tp *provider) TestObjectPut(t *testing.T) {
57 - ctx := context.Background()
58 + ctx, cancel := context.WithCancel(context.Background())
59 + defer cancel()
60 api, err := tp.makeAPI(ctx)
61 if err != nil {
62 t.Fatal(err)
@@ -94,7 +96,8 @@ func (tp *provider) TestObjectPut(t *testing.T) {
96 }
97
98 func (tp *provider) TestObjectGet(t *testing.T) {
97 - ctx := context.Background()
99 + ctx, cancel := context.WithCancel(context.Background())
100 + defer cancel()
101 api, err := tp.makeAPI(ctx)
102 if err != nil {
103 t.Fatal(err)
@@ -116,7 +119,8 @@ func (tp *provider) TestObjectGet(t *testing.T) {
119 }
120
121 func (tp *provider) TestObjectData(t *testing.T) {
119 - ctx := context.Background()
122 + ctx, cancel := context.WithCancel(context.Background())
123 + defer cancel()
124 api, err := tp.makeAPI(ctx)
125 if err != nil {
126 t.Fatal(err)
@@ -143,7 +147,8 @@ func (tp *provider) TestObjectData(t *testing.T) {
147 }
148
149 func (tp *provider) TestObjectLinks(t *testing.T) {
146 - ctx := context.Background()
150 + ctx, cancel := context.WithCancel(context.Background())
151 + defer cancel()
152 api, err := tp.makeAPI(ctx)
153 if err != nil {
154 t.Fatal(err)
@@ -178,7 +183,8 @@ func (tp *provider) TestObjectLinks(t *testing.T) {
183 }
184
185 func (tp *provider) TestObjectStat(t *testing.T) {
181 - ctx := context.Background()
186 + ctx, cancel := context.WithCancel(context.Background())
187 + defer cancel()
188 api, err := tp.makeAPI(ctx)
189 if err != nil {
190 t.Fatal(err)
@@ -225,7 +231,8 @@ func (tp *provider) TestObjectStat(t *testing.T) {
231 }
232
233 func (tp *provider) TestObjectAddLink(t *testing.T) {
228 - ctx := context.Background()
234 + ctx, cancel := context.WithCancel(context.Background())
235 + defer cancel()
236 api, err := tp.makeAPI(ctx)
237 if err != nil {
238 t.Fatal(err)
@@ -265,7 +272,8 @@ func (tp *provider) TestObjectAddLink(t *testing.T) {
272 }
273
274 func (tp *provider) TestObjectAddLinkCreate(t *testing.T) {
268 - ctx := context.Background()
275 + ctx, cancel := context.WithCancel(context.Background())
276 + defer cancel()
277 api, err := tp.makeAPI(ctx)
278 if err != nil {
279 t.Fatal(err)
@@ -313,7 +321,8 @@ func (tp *provider) TestObjectAddLinkCreate(t *testing.T) {
321 }
322
323 func (tp *provider) TestObjectRmLink(t *testing.T) {
316 - ctx := context.Background()
324 + ctx, cancel := context.WithCancel(context.Background())
325 + defer cancel()
326 api, err := tp.makeAPI(ctx)
327 if err != nil {
328 t.Fatal(err)
@@ -345,7 +354,8 @@ func (tp *provider) TestObjectRmLink(t *testing.T) {
354 }
355
356 func (tp *provider) TestObjectAddData(t *testing.T) {
348 - ctx := context.Background()
357 + ctx, cancel := context.WithCancel(context.Background())
358 + defer cancel()
359 api, err := tp.makeAPI(ctx)
360 if err != nil {
361 t.Fatal(err)
@@ -374,7 +384,8 @@ func (tp *provider) TestObjectAddData(t *testing.T) {
384 }
385
386 func (tp *provider) TestObjectSetData(t *testing.T) {
377 - ctx := context.Background()
387 + ctx, cancel := context.WithCancel(context.Background())
388 + defer cancel()
389 api, err := tp.makeAPI(ctx)
390 if err != nil {
391 t.Fatal(err)
@@ -403,7 +414,8 @@ func (tp *provider) TestObjectSetData(t *testing.T) {
414 }
415
416 func (tp *provider) TestDiffTest(t *testing.T) {
406 - ctx := context.Background()
417 + ctx, cancel := context.WithCancel(context.Background())
418 + defer cancel()
419 api, err := tp.makeAPI(ctx)
420 if err != nil {
421 t.Fatal(err)
core/coreiface/tests/path.go
+10 -5
@@ -18,7 +18,8 @@ func (tp *provider) TestPath(t *testing.T) {
18 }
19
20 func (tp *provider) TestMutablePath(t *testing.T) {
21 - ctx := context.Background()
21 + ctx, cancel := context.WithCancel(context.Background())
22 + defer cancel()
23 api, err := tp.makeAPI(ctx)
24 if err != nil {
25 t.Fatal(err)
@@ -45,7 +46,8 @@ func (tp *provider) TestMutablePath(t *testing.T) {
46 }
47
48 func (tp *provider) TestPathRemainder(t *testing.T) {
48 - ctx := context.Background()
49 + ctx, cancel := context.WithCancel(context.Background())
50 + defer cancel()
51 api, err := tp.makeAPI(ctx)
52 if err != nil {
53 t.Fatal(err)
@@ -72,7 +74,8 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
74 }
75
76 func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
75 - ctx := context.Background()
77 + ctx, cancel := context.WithCancel(context.Background())
78 + defer cancel()
79 api, err := tp.makeAPI(ctx)
80 if err != nil {
81 t.Fatal(err)
@@ -103,7 +106,8 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
106 }
107
108 func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
106 - ctx := context.Background()
109 + ctx, cancel := context.WithCancel(context.Background())
110 + defer cancel()
111 api, err := tp.makeAPI(ctx)
112 if err != nil {
113 t.Fatal(err)
@@ -126,7 +130,8 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
130 }
131
132 func (tp *provider) TestPathRoot(t *testing.T) {
129 - ctx := context.Background()
133 + ctx, cancel := context.WithCancel(context.Background())
134 + defer cancel()
135 api, err := tp.makeAPI(ctx)
136 if err != nil {
137 t.Fatal(err)
core/coreiface/tests/pin.go
+6 -3
@@ -15,7 +15,8 @@ func (tp *provider) TestPin(t *testing.T) {
15 }
16
17 func (tp *provider) TestPinAdd(t *testing.T) {
18 - ctx := context.Background()
18 + ctx, cancel := context.WithCancel(context.Background())
19 + defer cancel()
20 api, err := tp.makeAPI(ctx)
21 if err != nil {
22 t.Error(err)
@@ -33,7 +34,8 @@ func (tp *provider) TestPinAdd(t *testing.T) {
34 }
35
36 func (tp *provider) TestPinSimple(t *testing.T) {
36 - ctx := context.Background()
37 + ctx, cancel := context.WithCancel(context.Background())
38 + defer cancel()
39 api, err := tp.makeAPI(ctx)
40 if err != nil {
41 t.Error(err)
@@ -82,7 +84,8 @@ func (tp *provider) TestPinSimple(t *testing.T) {
84 }
85
86 func (tp *provider) TestPinRecursive(t *testing.T) {
85 - ctx := context.Background()
87 + ctx, cancel := context.WithCancel(context.Background())
88 + defer cancel()
89 api, err := tp.makeAPI(ctx)
90 if err != nil {
91 t.Error(err)
core/coreiface/tests/unixfs.go
+23 -12
@@ -79,7 +79,8 @@ func wrapped(name string) func(f files.Node) files.Node {
79 }
80
81 func (tp *provider) TestAdd(t *testing.T) {
82 - ctx := context.Background()
82 + ctx, cancel := context.WithCancel(context.Background())
83 + defer cancel()
84 api, err := tp.makeAPI(ctx)
85 if err != nil {
86 t.Error(err)
@@ -536,7 +537,8 @@ func (tp *provider) TestAdd(t *testing.T) {
537 }
538
539 func (tp *provider) TestAddPinned(t *testing.T) {
539 - ctx := context.Background()
540 + ctx, cancel := context.WithCancel(context.Background())
541 + defer cancel()
542 api, err := tp.makeAPI(ctx)
543 if err != nil {
544 t.Error(err)
@@ -558,7 +560,8 @@ func (tp *provider) TestAddPinned(t *testing.T) {
560 }
561
562 func (tp *provider) TestAddHashOnly(t *testing.T) {
561 - ctx := context.Background()
563 + ctx, cancel := context.WithCancel(context.Background())
564 + defer cancel()
565 api, err := tp.makeAPI(ctx)
566 if err != nil {
567 t.Error(err)
@@ -583,7 +586,8 @@ func (tp *provider) TestAddHashOnly(t *testing.T) {
586 }
587
588 func (tp *provider) TestGetEmptyFile(t *testing.T) {
586 - ctx := context.Background()
589 + ctx, cancel := context.WithCancel(context.Background())
590 + defer cancel()
591 api, err := tp.makeAPI(ctx)
592 if err != nil {
593 t.Fatal(err)
@@ -615,7 +619,8 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
619 }
620
621 func (tp *provider) TestGetDir(t *testing.T) {
618 - ctx := context.Background()
622 + ctx, cancel := context.WithCancel(context.Background())
623 + defer cancel()
624 api, err := tp.makeAPI(ctx)
625 if err != nil {
626 t.Error(err)
@@ -647,7 +652,8 @@ func (tp *provider) TestGetDir(t *testing.T) {
652 }
653
654 func (tp *provider) TestGetNonUnixfs(t *testing.T) {
650 - ctx := context.Background()
655 + ctx, cancel := context.WithCancel(context.Background())
656 + defer cancel()
657 api, err := tp.makeAPI(ctx)
658 if err != nil {
659 t.Error(err)
@@ -666,7 +672,8 @@ func (tp *provider) TestGetNonUnixfs(t *testing.T) {
672 }
673
674 func (tp *provider) TestLs(t *testing.T) {
669 - ctx := context.Background()
675 + ctx, cancel := context.WithCancel(context.Background())
676 + defer cancel()
677 api, err := tp.makeAPI(ctx)
678 if err != nil {
679 t.Error(err)
@@ -702,7 +709,8 @@ func (tp *provider) TestLs(t *testing.T) {
709 }
710
711 func (tp *provider) TestEntriesExpired(t *testing.T) {
705 - ctx := context.Background()
712 + ctx, cancel := context.WithCancel(context.Background())
713 + defer cancel()
714 api, err := tp.makeAPI(ctx)
715 if err != nil {
716 t.Error(err)
@@ -718,7 +726,7 @@ func (tp *provider) TestEntriesExpired(t *testing.T) {
726 t.Error(err)
727 }
728
721 - ctx, cancel := context.WithCancel(ctx)
729 + ctx, cancel = context.WithCancel(ctx)
730
731 nd, err := api.Unixfs().Get(ctx, p)
732 if err != nil {
@@ -745,7 +753,8 @@ func (tp *provider) TestEntriesExpired(t *testing.T) {
753 }
754
755 func (tp *provider) TestLsEmptyDir(t *testing.T) {
748 - ctx := context.Background()
756 + ctx, cancel := context.WithCancel(context.Background())
757 + defer cancel()
758 api, err := tp.makeAPI(ctx)
759 if err != nil {
760 t.Error(err)
@@ -773,7 +782,8 @@ func (tp *provider) TestLsEmptyDir(t *testing.T) {
782
783 // TODO(lgierth) this should test properly, with len(links) > 0
784 func (tp *provider) TestLsNonUnixfs(t *testing.T) {
776 - ctx := context.Background()
785 + ctx, cancel := context.WithCancel(context.Background())
786 + defer cancel()
787 api, err := tp.makeAPI(ctx)
788 if err != nil {
789 t.Error(err)
@@ -830,7 +840,8 @@ func (f *closeTestF) Close() error {
840 }
841
842 func (tp *provider) TestAddCloses(t *testing.T) {
833 - ctx := context.Background()
843 + ctx, cancel := context.WithCancel(context.Background())
844 + defer cancel()
845 api, err := tp.makeAPI(ctx)
846 if err != nil {
847 t.Error(err)