Replace context.TODO in test files with context.Background
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Aug 23, 2015 at 19:55 UTC
30e03b2da610b158ff061769080594dacc39df2b
12 files changed
+30
-28
blockservice/test/blocks_test.go
+2
-2
@@ -42,7 +42,7 @@ func TestBlocks(t *testing.T) {
42
t.Error("returned key is not equal to block key", err)
43
}
44
45
- ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5)
45
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
46
defer cancel()
47
b2, err := bs.GetBlock(ctx, b.Key())
48
if err != nil {
@@ -76,7 +76,7 @@ func TestGetBlocksSequential(t *testing.T) {
76
t.Log("one instance at a time, get blocks concurrently")
77
78
for i := 1; i < len(servs); i++ {
79
- ctx, cancel := context.WithTimeout(context.TODO(), time.Second*50)
79
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*50)
80
defer cancel()
81
out := servs[i].GetBlocks(ctx, keys)
82
gotten := make(map[key.Key]*blocks.Block)
core/core_test.go
+1
-1
@@ -10,7 +10,7 @@ import (
10
)
11
12
func TestInitialization(t *testing.T) {
13
- ctx := context.TODO()
13
+ ctx := context.Background()
14
id := testIdentity
15
16
good := []*config.Config{
core/coreunix/metadata_test.go
+3
-2
@@ -30,6 +30,7 @@ func getDagserv(t *testing.T) merkledag.DAGService {
30
}
31
32
func TestMetadata(t *testing.T) {
33
+ ctx := context.Background()
34
// Make some random node
35
ds := getDagserv(t)
36
data := make([]byte, 1000)
@@ -64,12 +65,12 @@ func TestMetadata(t *testing.T) {
65
t.Fatalf("something went wrong in conversion: '%s' != '%s'", rec.MimeType, m.MimeType)
66
}
67
67
- retnode, err := ds.Get(context.Background(), key.B58KeyDecode(mdk))
68
+ retnode, err := ds.Get(ctx, key.B58KeyDecode(mdk))
69
if err != nil {
70
t.Fatal(err)
71
}
72
72
- ndr, err := uio.NewDagReader(context.TODO(), retnode, ds)
73
+ ndr, err := uio.NewDagReader(ctx, retnode, ds)
74
if err != nil {
75
t.Fatal(err)
76
}
exchange/bitswap/bitswap_test.go
+7
-6
@@ -144,6 +144,7 @@ func TestLargeFileTwoPeers(t *testing.T) {
144
}
145
146
func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
147
+ ctx := context.Background()
148
if testing.Short() {
149
t.SkipNow()
150
}
@@ -161,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
162
first := instances[0]
163
for _, b := range blocks {
164
blkeys = append(blkeys, b.Key())
164
- first.Exchange.HasBlock(context.Background(), b)
165
+ first.Exchange.HasBlock(ctx, b)
166
}
167
168
t.Log("Distribute!")
@@ -171,7 +172,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
172
wg.Add(1)
173
go func(inst Instance) {
174
defer wg.Done()
174
- outch, err := inst.Exchange.GetBlocks(context.TODO(), blkeys)
175
+ outch, err := inst.Exchange.GetBlocks(ctx, blkeys)
176
if err != nil {
177
t.Fatal(err)
178
}
@@ -228,7 +229,7 @@ func TestSendToWantingPeer(t *testing.T) {
229
230
alpha := bg.Next()
231
// peerA requests and waits for block alpha
231
- ctx, cancel := context.WithTimeout(context.TODO(), waitTime)
232
+ ctx, cancel := context.WithTimeout(context.Background(), waitTime)
233
defer cancel()
234
alphaPromise, err := peerA.Exchange.GetBlocks(ctx, []key.Key{alpha.Key()})
235
if err != nil {
@@ -236,7 +237,7 @@ func TestSendToWantingPeer(t *testing.T) {
237
}
238
239
// peerB announces to the network that he has block alpha
239
- ctx, cancel = context.WithTimeout(context.TODO(), timeout)
240
+ ctx, cancel = context.WithTimeout(context.Background(), timeout)
241
defer cancel()
242
err = peerB.Exchange.HasBlock(ctx, alpha)
243
if err != nil {
@@ -265,12 +266,12 @@ func TestBasicBitswap(t *testing.T) {
266
267
instances := sg.Instances(2)
268
blocks := bg.Blocks(1)
268
- err := instances[0].Exchange.HasBlock(context.TODO(), blocks[0])
269
+ err := instances[0].Exchange.HasBlock(context.Background(), blocks[0])
270
if err != nil {
271
t.Fatal(err)
272
}
273
273
- ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5)
274
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
275
defer cancel()
276
blk, err := instances[1].Exchange.GetBlock(ctx, blocks[0].Key())
277
if err != nil {
exchange/bitswap/notifications/notifications_test.go
+1
-1
@@ -103,7 +103,7 @@ func TestDuplicateSubscribe(t *testing.T) {
103
func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) {
104
n := New()
105
defer n.Shutdown()
106
- ch := n.Subscribe(context.TODO()) // no keys provided
106
+ ch := n.Subscribe(context.Background()) // no keys provided
107
if _, ok := <-ch; ok {
108
t.Fatal("should be closed if no keys provided")
109
}
exchange/bitswap/testutils.go
+1
-1
@@ -18,7 +18,7 @@ import (
18
// WARNING: this uses RandTestBogusIdentity DO NOT USE for NON TESTS!
19
func NewTestSessionGenerator(
20
net tn.Network) SessionGenerator {
21
- ctx, cancel := context.WithCancel(context.TODO())
21
+ ctx, cancel := context.WithCancel(context.Background())
22
return SessionGenerator{
23
net: net,
24
seq: 0,
fuse/ipns/ipns_test.go
+1
-1
@@ -106,7 +106,7 @@ func setupIpnsTest(t *testing.T, node *core.IpfsNode) (*core.IpfsNode, *fstest.M
106
t.Fatal(err)
107
}
108
109
- ipnsfs, err := nsfs.NewFilesystem(context.TODO(), node.DAG, node.Namesys, node.Pinning, node.PrivateKey)
109
+ ipnsfs, err := nsfs.NewFilesystem(context.Background(), node.DAG, node.Namesys, node.Pinning, node.PrivateKey)
110
if err != nil {
111
t.Fatal(err)
112
}
importer/importer_test.go
+2
-2
@@ -45,7 +45,7 @@ func TestBalancedDag(t *testing.T) {
45
t.Fatal(err)
46
}
47
48
- dr, err := uio.NewDagReader(context.TODO(), nd, ds)
48
+ dr, err := uio.NewDagReader(context.Background(), nd, ds)
49
if err != nil {
50
t.Fatal(err)
51
}
@@ -102,7 +102,7 @@ func BenchmarkTrickleReadFull(b *testing.B) {
102
103
func runReadBench(b *testing.B, nd *dag.Node, ds dag.DAGService) {
104
for i := 0; i < b.N; i++ {
105
- ctx, cancel := context.WithCancel(context.TODO())
105
+ ctx, cancel := context.WithCancel(context.Background())
106
read, err := uio.NewDagReader(ctx, nd, ds)
107
if err != nil {
108
b.Fatal(err)
importer/trickle/trickle_test.go
+3
-3
@@ -443,7 +443,7 @@ func TestAppend(t *testing.T) {
443
r := bytes.NewReader(should[nbytes/2:])
444
blks, errs := chunk.Chan(chunk.NewSizeSplitter(r, 500))
445
446
- ctx := context.TODO()
446
+ ctx := context.Background()
447
nnode, err := TrickleAppend(ctx, nd, dbp.New(blks, errs))
448
if err != nil {
449
t.Fatal(err)
@@ -492,7 +492,7 @@ func TestMultipleAppends(t *testing.T) {
492
493
spl := chunk.SizeSplitterGen(500)
494
495
- ctx := context.TODO()
495
+ ctx := context.Background()
496
for i := 0; i < len(should); i++ {
497
blks, errs := chunk.Chan(spl(bytes.NewReader(should[i : i+1])))
498
@@ -540,7 +540,7 @@ func TestAppendSingleBytesToEmpty(t *testing.T) {
540
541
blks, errs := chunk.Chan(spl(bytes.NewReader(data[:1])))
542
543
- ctx := context.TODO()
543
+ ctx := context.Background()
544
nnode, err := TrickleAppend(ctx, nd, dbp.New(blks, errs))
545
if err != nil {
546
t.Fatal(err)
merkledag/merkledag_test.go
+6
-6
@@ -155,6 +155,7 @@ func TestBatchFetchDupBlock(t *testing.T) {
155
}
156
157
func runBatchFetchTest(t *testing.T, read io.Reader) {
158
+ ctx := context.Background()
159
var dagservs []DAGService
160
for _, bsi := range bstest.Mocks(5) {
161
dagservs = append(dagservs, NewDAGService(bsi))
@@ -169,7 +170,7 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
170
171
t.Log("finished setup.")
172
172
- dagr, err := uio.NewDagReader(context.TODO(), root, dagservs[0])
173
+ dagr, err := uio.NewDagReader(ctx, root, dagservs[0])
174
if err != nil {
175
t.Fatal(err)
176
}
@@ -196,13 +197,13 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
197
wg.Add(1)
198
go func(i int) {
199
defer wg.Done()
199
- first, err := dagservs[i].Get(context.Background(), k)
200
+ first, err := dagservs[i].Get(ctx, k)
201
if err != nil {
202
t.Fatal(err)
203
}
204
fmt.Println("Got first node back.")
205
205
- read, err := uio.NewDagReader(context.TODO(), first, dagservs[i])
206
+ read, err := uio.NewDagReader(ctx, first, dagservs[i])
207
if err != nil {
208
t.Fatal(err)
209
}
@@ -266,8 +267,7 @@ func assertCanGet(t *testing.T, ds DAGService, n *Node) {
267
t.Fatal(err)
268
}
269
269
- _, err = ds.Get(context.TODO(), k)
270
- if err != nil {
270
+ if _, err := ds.Get(context.Background(), k); err != nil {
271
t.Fatal(err)
272
}
273
}
@@ -281,7 +281,7 @@ func TestCantGet(t *testing.T) {
281
t.Fatal(err)
282
}
283
284
- _, err = dsp.ds.Get(context.TODO(), k)
284
+ _, err = dsp.ds.Get(context.Background(), k)
285
if !strings.Contains(err.Error(), "not found") {
286
t.Fatal("expected err not found, got: ", err)
287
}
merkledag/utils/utils_test.go
+1
-1
@@ -104,7 +104,7 @@ func testInsert(t *testing.T, e *Editor, path, data string, create bool, experr
104
}
105
}
106
107
- err = e.InsertNodeAtPath(context.TODO(), path, ck, c)
107
+ err = e.InsertNodeAtPath(context.Background(), path, ck, c)
108
if experr != "" {
109
var got string
110
if err != nil {
p2p/net/swarm/swarm_test.go
+2
-2
@@ -288,13 +288,13 @@ func TestAddrBlocking(t *testing.T) {
288
swarms[1].Filters.AddDialFilter(block)
289
290
swarms[1].peers.AddAddr(swarms[0].LocalPeer(), swarms[0].ListenAddresses()[0], peer.PermanentAddrTTL)
291
- _, err = swarms[1].Dial(context.TODO(), swarms[0].LocalPeer())
291
+ _, err = swarms[1].Dial(ctx, swarms[0].LocalPeer())
292
if err == nil {
293
t.Fatal("dial should have failed")
294
}
295
296
swarms[0].peers.AddAddr(swarms[1].LocalPeer(), swarms[1].ListenAddresses()[0], peer.PermanentAddrTTL)
297
- _, err = swarms[0].Dial(context.TODO(), swarms[1].LocalPeer())
297
+ _, err = swarms[0].Dial(ctx, swarms[1].LocalPeer())
298
if err == nil {
299
t.Fatal("dial should have failed")
300
}