Skip to content

Commit

Permalink
unbreak itests
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Jun 29, 2022
1 parent e8c44ba commit 0c34699
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
37 changes: 23 additions & 14 deletions itests/deals_partial_retrieval_dm-level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -143,36 +144,44 @@ func TestDMLevelPartialRetrieval(t *testing.T) {
}

func testDMExportAsFile(ctx context.Context, client *kit.TestFullNode, expDirective api.ExportRef, tempDir string) error {
out, err := ioutil.TempFile(tempDir, "exp-test")
out := tempDir + string(os.PathSeparator) + "exp-test" + expDirective.Root.String()

fileDest := api.FileRef{
Path: out,
}
err := client.ClientExport(ctx, expDirective, fileDest)
if err != nil {
return err
}
defer out.Close() //nolint:errcheck

fileDest := api.FileRef{
Path: out.Name(),
}
err = client.ClientExport(ctx, expDirective, fileDest)
f, err := os.Open(out)
if err != nil {
return err
}
return validateDMUnixFile(out)

defer f.Close() //nolint:errcheck

return validateDMUnixFile(f)
}
func testV0RetrievalAsFile(ctx context.Context, client *kit.TestFullNode, retOrder api0.RetrievalOrder, tempDir string) error {
out, err := ioutil.TempFile(tempDir, "exp-test")
out := tempDir + string(os.PathSeparator) + "exp-test" + retOrder.Root.String()

cv0 := &api0.WrapperV1Full{client.FullNode} //nolint:govet
err := cv0.ClientRetrieve(ctx, retOrder, &api.FileRef{
Path: out,
})
if err != nil {
return err
}
defer out.Close() //nolint:errcheck

cv0 := &api0.WrapperV1Full{client.FullNode} //nolint:govet
err = cv0.ClientRetrieve(ctx, retOrder, &api.FileRef{
Path: out.Name(),
})
f, err := os.Open(out)
if err != nil {
return err
}
return validateDMUnixFile(out)

defer f.Close() //nolint:errcheck

return validateDMUnixFile(f)
}
func validateDMUnixFile(r io.Reader) error {
data, err := io.ReadAll(r)
Expand Down
19 changes: 10 additions & 9 deletions itests/deals_partial_retrieval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"time"
Expand Down Expand Up @@ -109,20 +108,17 @@ func TestPartialRetrieval(t *testing.T) {

// test retrieval of either data or constructing a partial selective-car
for _, retrieveAsCar := range []bool{false, true} {
outFile, err := ioutil.TempFile(t.TempDir(), "ret-file")
require.NoError(t, err)
defer outFile.Close() //nolint:errcheck
outFile := t.TempDir() + string(os.PathSeparator) + "ret-file" + retOrder.Root.String()

require.NoError(t, testGenesisRetrieval(
ctx,
client,
retOrder,
eref,
&api.FileRef{
Path: outFile.Name(),
Path: outFile,
IsCAR: retrieveAsCar,
},
outFile,
))

// UGH if I do not sleep here, I get things like:
Expand Down Expand Up @@ -152,7 +148,6 @@ func TestPartialRetrieval(t *testing.T) {
DAGs: []api.DagSpec{{DataSelector: &textSelectorNonexistent}},
},
&api.FileRef{},
nil,
),
fmt.Sprintf("parsing dag spec: path selection does not match a node within %s", carRoot),
)
Expand All @@ -173,13 +168,12 @@ func TestPartialRetrieval(t *testing.T) {
DAGs: []api.DagSpec{{DataSelector: &textSelectorNonLink}},
},
&api.FileRef{},
nil,
),
fmt.Sprintf("parsing dag spec: error while locating partial retrieval sub-root: unsupported selection path '%s' does not correspond to a block boundary (a.k.a. CID link)", textSelectorNonLink),
)
}

func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrder api.RetrievalOrder, eref api.ExportRef, retRef *api.FileRef, outFile *os.File) error {
func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrder api.RetrievalOrder, eref api.ExportRef, retRef *api.FileRef) error {

if retOrder.Total.Nil() {
retOrder.Total = big.Zero()
Expand All @@ -205,6 +199,13 @@ func testGenesisRetrieval(ctx context.Context, client *kit.TestFullNode, retOrde
return err
}

outFile, err := os.Open(retRef.Path)
if err != nil {
return err
}

defer outFile.Close() //nolint:errcheck

var data []byte
if !retRef.IsCAR {

Expand Down
21 changes: 7 additions & 14 deletions itests/kit/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -323,10 +322,7 @@ func (dh *DealHarness) PerformRetrieval(ctx context.Context, deal *cid.Cid, root
offer = offers[0]
}

carFile, err := ioutil.TempFile(dh.t.TempDir(), "ret-car")
require.NoError(dh.t, err)

defer carFile.Close() //nolint:errcheck
carFile := dh.t.TempDir() + string(os.PathSeparator) + "ret-car-" + root.String()

caddr, err := dh.client.WalletDefaultAddress(ctx)
require.NoError(dh.t, err)
Expand Down Expand Up @@ -367,16 +363,16 @@ consumeEvents:
DealID: retrievalRes.DealID,
},
api.FileRef{
Path: carFile.Name(),
Path: carFile,
IsCAR: carExport,
}))

ret := carFile.Name()
ret := carFile

return ret
}

func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) (out *os.File) {
func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) string {
bserv := dstest.Bserv()
ch, err := car.LoadCar(ctx, bserv.Blockstore(), file)
require.NoError(dh.t, err)
Expand All @@ -391,12 +387,9 @@ func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) (o
fil, err := unixfile.NewUnixfsFile(ctx, dserv, nd)
require.NoError(dh.t, err)

tmpfile, err := ioutil.TempFile(dh.t.TempDir(), "file-in-car")
require.NoError(dh.t, err)

defer tmpfile.Close() //nolint:errcheck
tmpfile := dh.t.TempDir() + string(os.PathSeparator) + "file-in-car" + b.Cid().String()

err = files.WriteTo(fil, tmpfile.Name())
err = files.WriteTo(fil, tmpfile)
require.NoError(dh.t, err)

return tmpfile
Expand Down Expand Up @@ -452,7 +445,7 @@ func (dh *DealHarness) RunConcurrentDeals(opts RunConcurrentDealsOpts) {
actualFile := dh.ExtractFileFromCAR(ctx, f)
require.NoError(dh.t, f.Close())

AssertFilesEqual(dh.t, inPath, actualFile.Name())
AssertFilesEqual(dh.t, inPath, actualFile)
} else {
AssertFilesEqual(dh.t, inPath, outPath)
}
Expand Down
6 changes: 2 additions & 4 deletions lib/unixfs/filestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ func TestRoundtripUnixFS_Filestore(t *testing.T) {
require.Equal(t, inputContents, bz2)
}

// creates a new tempdir each time, guaranteeing uniqueness
func newTmpFile(t *testing.T) string {
f, err := os.CreateTemp("", "")
require.NoError(t, err)
require.NoError(t, f.Close())
return f.Name()
return t.TempDir() + string(os.PathSeparator) + "tmp"
}

func genInputFile(t *testing.T) (filepath string, contents []byte) {
Expand Down

0 comments on commit 0c34699

Please sign in to comment.