From 77e0e6846a10c5bb970c44eebda740d556535ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 22 Jul 2020 11:12:26 +0200 Subject: [PATCH] context.TODO() a few places that now require a context This is due to most of the data pipeline now requiring a context. There is very few places where this context is needed but wiring a context up to there quickly grow into a massive change that I'm not able to deal with. I used instead context.TODO() tofix the compilation while keeping the same behavior as before. --- impl/graphsync_test.go | 4 ++-- storeutil/storeutil.go | 5 +++-- storeutil/storeutil_test.go | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/impl/graphsync_test.go b/impl/graphsync_test.go index 80d8a47e..73ca96ac 100644 --- a/impl/graphsync_test.go +++ b/impl/graphsync_test.go @@ -677,7 +677,7 @@ func TestUnixFSFetch(t *testing.T) { return nil, errors.New("Incorrect Link Type") } // read block from one store - block, err := bs.Get(c.Cid) + block, err := bs.Get(context.TODO(), c.Cid) if err != nil { return nil, err } @@ -697,7 +697,7 @@ func TestUnixFSFetch(t *testing.T) { if err != nil { return err } - return bs.Put(block) + return bs.Put(context.TODO(), block) } return &buf, committer, nil } diff --git a/storeutil/storeutil.go b/storeutil/storeutil.go index f438c878..fdd0615e 100644 --- a/storeutil/storeutil.go +++ b/storeutil/storeutil.go @@ -2,6 +2,7 @@ package storeutil import ( "bytes" + "context" "fmt" "io" @@ -19,7 +20,7 @@ func LoaderForBlockstore(bs bstore.Blockstore) ipld.Loader { if !ok { return nil, fmt.Errorf("Unsupported Link Type") } - block, err := bs.Get(asCidLink.Cid) + block, err := bs.Get(context.TODO(), asCidLink.Cid) if err != nil { return nil, err } @@ -41,7 +42,7 @@ func StorerForBlockstore(bs bstore.Blockstore) ipld.Storer { if err != nil { return err } - return bs.Put(block) + return bs.Put(context.TODO(), block) } return &buffer, committer, nil } diff --git a/storeutil/storeutil_test.go b/storeutil/storeutil_test.go index 6ca3f9f1..c923fdd8 100644 --- a/storeutil/storeutil_test.go +++ b/storeutil/storeutil_test.go @@ -1,6 +1,7 @@ package storeutil import ( + "context" "io/ioutil" "testing" @@ -16,9 +17,10 @@ import ( ) func TestLoader(t *testing.T) { + ctx := context.Background() store := bstore.NewBlockstore(dss.MutexWrap(datastore.NewMapDatastore())) blk := testutil.GenerateBlocksOfSize(1, 1000)[0] - err := store.Put(blk) + err := store.Put(ctx, blk) require.NoError(t, err, "Unable to put block to store") loader := LoaderForBlockstore(store) data, err := loader(cidlink.Link{Cid: blk.Cid()}, ipld.LinkContext{}) @@ -30,6 +32,7 @@ func TestLoader(t *testing.T) { } func TestStorer(t *testing.T) { + ctx := context.Background() store := bstore.NewBlockstore(dss.MutexWrap(datastore.NewMapDatastore())) blk := testutil.GenerateBlocksOfSize(1, 1000)[0] storer := StorerForBlockstore(store) @@ -39,6 +42,6 @@ func TestStorer(t *testing.T) { require.NoError(t, err, "Unable to write data to buffer") err = commit(cidlink.Link{Cid: blk.Cid()}) require.NoError(t, err, "Unable to commit with storer function") - _, err = store.Get(blk.Cid()) + _, err = store.Get(ctx, blk.Cid()) require.NoError(t, err, "Block not written to store") }