mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 23:42:20 +08:00
Replace context.TODO in test files with context.Background
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
@ -144,6 +144,7 @@ func TestLargeFileTwoPeers(t *testing.T) {
|
||||
}
|
||||
|
||||
func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
|
||||
ctx := context.Background()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
@ -161,7 +162,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
|
||||
first := instances[0]
|
||||
for _, b := range blocks {
|
||||
blkeys = append(blkeys, b.Key())
|
||||
first.Exchange.HasBlock(context.Background(), b)
|
||||
first.Exchange.HasBlock(ctx, b)
|
||||
}
|
||||
|
||||
t.Log("Distribute!")
|
||||
@ -171,7 +172,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
|
||||
wg.Add(1)
|
||||
go func(inst Instance) {
|
||||
defer wg.Done()
|
||||
outch, err := inst.Exchange.GetBlocks(context.TODO(), blkeys)
|
||||
outch, err := inst.Exchange.GetBlocks(ctx, blkeys)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -228,7 +229,7 @@ func TestSendToWantingPeer(t *testing.T) {
|
||||
|
||||
alpha := bg.Next()
|
||||
// peerA requests and waits for block alpha
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), waitTime)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), waitTime)
|
||||
defer cancel()
|
||||
alphaPromise, err := peerA.Exchange.GetBlocks(ctx, []key.Key{alpha.Key()})
|
||||
if err != nil {
|
||||
@ -236,7 +237,7 @@ func TestSendToWantingPeer(t *testing.T) {
|
||||
}
|
||||
|
||||
// peerB announces to the network that he has block alpha
|
||||
ctx, cancel = context.WithTimeout(context.TODO(), timeout)
|
||||
ctx, cancel = context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
err = peerB.Exchange.HasBlock(ctx, alpha)
|
||||
if err != nil {
|
||||
@ -265,12 +266,12 @@ func TestBasicBitswap(t *testing.T) {
|
||||
|
||||
instances := sg.Instances(2)
|
||||
blocks := bg.Blocks(1)
|
||||
err := instances[0].Exchange.HasBlock(context.TODO(), blocks[0])
|
||||
err := instances[0].Exchange.HasBlock(context.Background(), blocks[0])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*5)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
blk, err := instances[1].Exchange.GetBlock(ctx, blocks[0].Key())
|
||||
if err != nil {
|
||||
|
@ -103,7 +103,7 @@ func TestDuplicateSubscribe(t *testing.T) {
|
||||
func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) {
|
||||
n := New()
|
||||
defer n.Shutdown()
|
||||
ch := n.Subscribe(context.TODO()) // no keys provided
|
||||
ch := n.Subscribe(context.Background()) // no keys provided
|
||||
if _, ok := <-ch; ok {
|
||||
t.Fatal("should be closed if no keys provided")
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
// WARNING: this uses RandTestBogusIdentity DO NOT USE for NON TESTS!
|
||||
func NewTestSessionGenerator(
|
||||
net tn.Network) SessionGenerator {
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
return SessionGenerator{
|
||||
net: net,
|
||||
seq: 0,
|
||||
|
Reference in New Issue
Block a user