Skip to content

Commit

Permalink
feat: plumb through context changes (#28)
Browse files Browse the repository at this point in the history
This commit was moved from ipfs/go-fetcher@d2ffddc
  • Loading branch information
guseggert authored Nov 10, 2021
1 parent a22b7e0 commit ae9364a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
16 changes: 9 additions & 7 deletions fetcher/helpers/block_visitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/stretchr/testify/require"
)

var bg = context.Background()

func TestFetchGraphToBlocks(t *testing.T) {
block3, node3, link3 := testutil.EncodeBlock(fluent.MustBuildMap(basicnode.Prototype__Map{}, 1, func(na fluent.MapAssembler) {
na.AssembleEntry("three").AssignBool(true)
Expand Down Expand Up @@ -49,13 +51,13 @@ func TestFetchGraphToBlocks(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block1)
err := hasBlock.Exchange.HasBlock(bg, block1)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block2)
err = hasBlock.Exchange.HasBlock(bg, block2)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block3)
err = hasBlock.Exchange.HasBlock(bg, block3)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block4)
err = hasBlock.Exchange.HasBlock(bg, block4)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down Expand Up @@ -102,11 +104,11 @@ func TestFetchGraphToUniqueBlocks(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block1)
err := hasBlock.Exchange.HasBlock(bg, block1)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block2)
err = hasBlock.Exchange.HasBlock(bg, block2)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block3)
err = hasBlock.Exchange.HasBlock(bg, block3)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down
28 changes: 15 additions & 13 deletions fetcher/impl/blockservice/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/stretchr/testify/require"
)

var bg = context.Background()

func TestFetchIPLDPrimeNode(t *testing.T) {
block, node, _ := testutil.EncodeBlock(fluent.MustBuildMap(basicnode.Prototype__Map{}, 3, func(na fluent.MapAssembler) {
na.AssembleEntry("foo").AssignBool(true)
Expand All @@ -44,7 +46,7 @@ func TestFetchIPLDPrimeNode(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block)
err := hasBlock.Exchange.HasBlock(bg, block)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down Expand Up @@ -90,13 +92,13 @@ func TestFetchIPLDGraph(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block1)
err := hasBlock.Exchange.HasBlock(bg, block1)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block2)
err = hasBlock.Exchange.HasBlock(bg, block2)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block3)
err = hasBlock.Exchange.HasBlock(bg, block3)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block4)
err = hasBlock.Exchange.HasBlock(bg, block4)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down Expand Up @@ -150,7 +152,7 @@ func TestFetchIPLDPath(t *testing.T) {
defer hasBlock.Exchange.Close()

for _, blk := range []blocks.Block{block1, block2, block3, block4, block5} {
err := hasBlock.Exchange.HasBlock(blk)
err := hasBlock.Exchange.HasBlock(bg, blk)
require.NoError(t, err)
}

Expand Down Expand Up @@ -212,13 +214,13 @@ func TestHelpers(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block1)
err := hasBlock.Exchange.HasBlock(bg, block1)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block2)
err = hasBlock.Exchange.HasBlock(bg, block2)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block3)
err = hasBlock.Exchange.HasBlock(bg, block3)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block4)
err = hasBlock.Exchange.HasBlock(bg, block4)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down Expand Up @@ -329,11 +331,11 @@ func TestNodeReification(t *testing.T) {
hasBlock := peers[0]
defer hasBlock.Exchange.Close()

err := hasBlock.Exchange.HasBlock(block2)
err := hasBlock.Exchange.HasBlock(bg, block2)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block3)
err = hasBlock.Exchange.HasBlock(bg, block3)
require.NoError(t, err)
err = hasBlock.Exchange.HasBlock(block4)
err = hasBlock.Exchange.HasBlock(bg, block4)
require.NoError(t, err)

wantsBlock := peers[1]
Expand Down

0 comments on commit ae9364a

Please sign in to comment.