Skip to content

Commit

Permalink
Fix tests for multiminer
Browse files Browse the repository at this point in the history
  • Loading branch information
ischasny committed Nov 1, 2023
1 parent cc9e559 commit f052fe0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions cmd/booster-http/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestE2E(t *testing.T) {
req.NoError(boostAndMiner.AddClientProviderBalance(abi.NewTokenAmount(1e15)))

// Get the listen address of the miner
minerApiInfo, err := boostAndMiner.LotusMinerApiInfo()
minerApiInfos, err := boostAndMiner.LotusMinerApiInfos()
req.NoError(err)
fullNodeApiInfo, err := boostAndMiner.LotusFullNodeApiInfo()
req.NoError(err)
Expand All @@ -56,7 +56,7 @@ func TestE2E(t *testing.T) {
require.NoError(t, err)

t.Log("Starting booster-http")
runAndWaitForBoosterHttp(ctx, t, []string{minerApiInfo}, fullNodeApiInfo, boosterHttpPort, "--serve-pieces=false", "--serve-cars=true")
runAndWaitForBoosterHttp(ctx, t, minerApiInfos, fullNodeApiInfo, boosterHttpPort, "--serve-pieces=false", "--serve-cars=true")

cwd, err := os.Getwd()
req.NoError(err)
Expand Down
48 changes: 25 additions & 23 deletions cmd/booster-http/multiminer_retrieval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,36 @@ func TestMultiMinerHttpRetrieval(t *testing.T) {

runAndWaitForBoosterHttp(ctx, t, minerApiInfos, fullNode2ApiInfo, port)

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/ipfs/%s", port, rt.RootCid.String()), nil)
require.NoError(t, err)
req.Header.Set("Accept", "application/vnd.ipld.car")
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
if resp.StatusCode != 200 {
body, err := io.ReadAll(resp.Body)
for i, rootCid := range rt.RootCids {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/ipfs/%s", port, rootCid.String()), nil)
require.NoError(t, err)
msg := fmt.Sprintf("Failed to fetch root cid: %s\n%s", resp.Status, string(body))
require.Fail(t, msg)
}
req.Header.Set("Accept", "application/vnd.ipld.car")
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
if resp.StatusCode != 200 {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
msg := fmt.Sprintf("Failed to fetch root cid: %s\n%s", resp.Status, string(body))
require.Fail(t, msg)
}

wantCids, err := testutil.CidsInCar(rt.CarFilepaths[0])
require.NoError(t, err)
wantCids, err := testutil.CidsInCar(rt.CarFilepaths[i])
require.NoError(t, err)

cr, err := car.NewBlockReader(resp.Body)
require.NoError(t, err)
require.Equal(t, []cid.Cid{rt.RootCid}, cr.Roots)
cnt := 0
for ; ; cnt++ {
next, err := cr.Next()
if err != nil {
require.Equal(t, io.EOF, err)
break
cr, err := car.NewBlockReader(resp.Body)
require.NoError(t, err)
require.Equal(t, []cid.Cid{rootCid}, cr.Roots)
cnt := 0
for ; ; cnt++ {
next, err := cr.Next()
if err != nil {
require.Equal(t, io.EOF, err)
break
}
require.Contains(t, wantCids, next.Cid())
}
require.Contains(t, wantCids, next.Cid())
require.Equal(t, len(wantCids), cnt)
}
require.Equal(t, len(wantCids), cnt)
})
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/booster-http/trustless_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestTrustlessGateway(t *testing.T) {
req.NoError(boostAndMiner.AddClientProviderBalance(abi.NewTokenAmount(1e15)))

// Get the listen address of the miner
minerApiInfo, err := boostAndMiner.LotusMinerApiInfo()
minerApiInfos, err := boostAndMiner.LotusMinerApiInfos()
req.NoError(err)
fullNodeApiInfo, err := boostAndMiner.LotusFullNodeApiInfo()
req.NoError(err)
Expand All @@ -52,7 +52,7 @@ func TestTrustlessGateway(t *testing.T) {
port, err := testutil.FreePort()
require.NoError(t, err)

runAndWaitForBoosterHttp(ctx, t, []string{minerApiInfo}, fullNodeApiInfo, port, "--serve-pieces=false", "--serve-cars=true")
runAndWaitForBoosterHttp(ctx, t, minerApiInfos, fullNodeApiInfo, port, "--serve-pieces=false", "--serve-cars=true")

for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
Expand Down Expand Up @@ -130,7 +130,7 @@ func dealTestCarInParts(ctx context.Context, t *testing.T, boostAndMiner *framew

// Make a storage deal on the first boost, which will store the index to
// LID and store the data on the first miner
res, err := boostAndMiner.MakeDummyDeal(dealUuid, file.Name(), rootCid, server.URL+"/"+filepath.Base(file.Name()), false)
res, err := boostAndMiner.MakeDummyDeal(dealUuid, file.Name(), rootCid, server.URL+"/"+filepath.Base(file.Name()), false, boostAndMiner.MinerAddrs[0])
req.NoError(err)
t.Logf("created MarketDummyDeal %s", spew.Sdump(res))
req.True(res.Result.Accepted)
Expand Down
10 changes: 5 additions & 5 deletions itests/shared/multiminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func RunMultiminerRetrievalTest(t *testing.T, rt func(ctx context.Context, t *te
defer server.Close()

// make two deals, one on miner1 and one on miner2 to make sure that both are retrievable
createDealFunc := func(minerAddr address.Address) (cid.Cid, string) {
createDealFunc := func(minerAddr address.Address) (cid.Cid, string, string) {
// Create a new dummy deal
t.Logf("creating dummy deal")
dealUuid := uuid.New()
Expand All @@ -83,16 +83,16 @@ func RunMultiminerRetrievalTest(t *testing.T, rt func(ctx context.Context, t *te
err = boostAndMiners.WaitForDealAddedToSector(dealUuid)
require.NoError(t, err)

return rootCid, randomFilepath
return rootCid, randomFilepath, carFilepath
}

rootCid1, filePath1 := createDealFunc(boostAndMiners.MinerAddrs[0])
rootCid2, filePath2 := createDealFunc(boostAndMiners.MinerAddrs[1])
rootCid1, filePath1, carFilePath1 := createDealFunc(boostAndMiners.MinerAddrs[0])
rootCid2, filePath2, carFilePath2 := createDealFunc(boostAndMiners.MinerAddrs[1])

rt(ctx, t, &RetrievalTest{
BoostAndMiners: boostAndMiners,
SampleFilePaths: []string{filePath1, filePath2},
CarFilepaths: []string{carFilepath, carFilepath},
CarFilepaths: []string{carFilePath1, carFilePath2},
RootCids: []cid.Cid{rootCid1, rootCid2},
})
}

0 comments on commit f052fe0

Please sign in to comment.