Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Fix shadowing of unused var #83

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion carserver/station_api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *StationAPIImpl) createOrUpdateReqStatsUnlocked(ctx context.Context, cre
if err == datastore.ErrNotFound {
stats := station.ReqStats{}
createFn(&stats)
bz, err = json.Marshal(stats)
bz, err := json.Marshal(stats)
if err != nil {
return fmt.Errorf("failed to marshal retrieval stats to json: %w", err)
}
Expand Down
14 changes: 12 additions & 2 deletions carstore/carstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package carstore
import (
"context"
"errors"
"fmt"
"sync"
"testing"
"time"

"golang.org/x/sync/errgroup"

"github.com/ipld/go-ipld-prime/codec/dagcbor"
"github.com/ipld/go-ipld-prime/multicodec"

"github.com/filecoin-project/saturn-l2/station"

cid "github.com/ipfs/go-cid"

"golang.org/x/sync/errgroup"

"github.com/filecoin-project/dagstore"

"github.com/filecoin-project/saturn-l2/logs"
Expand Down Expand Up @@ -47,20 +48,25 @@ func TestPersistentCache(t *testing.T) {
csh.assertStorageStats(t, station.StorageStats{BytesCurrentlyStored: 0})
// first hit -> not found
csh.fetchAndAssertNotFound(reqID, rootcid)
fmt.Println("\n data downloaded after first hit is", csh.ms.nDownloaded())

// second hit -> not found
csh.fetchAndAssertNotFound(reqID, rootcid)
fmt.Println("\n data downloaded after second hit is", csh.ms.nDownloaded())

// wait till l2 has fetched and cached it
csh.assertAvailable(t, ctx, rootcid)
fmt.Println("\n data downloaded after caching is", csh.ms.nDownloaded())

// third hit -> found
csh.fetchAndAssertFound(ctx, reqID, rootcid)
require.EqualValues(t, len(bz), csh.ms.nDownloaded())
fmt.Println("\n data downloaded is after third hit", csh.ms.nDownloaded())

// fourth hit -> found
csh.fetchAndAssertFound(ctx, reqID, rootcid)
require.EqualValues(t, len(bz), csh.ms.nDownloaded())
fmt.Println("\n data downloaded after fetching success is", csh.ms.nDownloaded())

// wait for shard to become reclaimable again
require.Eventually(t, func() bool {
Expand All @@ -76,14 +82,18 @@ func TestPersistentCache(t *testing.T) {
require.Len(t, res.Shards, 1)
csh.assertStorageStats(t, station.StorageStats{BytesCurrentlyStored: 0})

fmt.Println("\n data downloaded after dagstore GC is", csh.ms.nDownloaded())

// fetch car -> fails as we do not have it but will trigger a fetch again
csh.fetchAndAssertNotFound(reqID, rootcid)
fmt.Println("\n data downloaded after fetch trigger fails is", csh.ms.nDownloaded())

// fetch car -> works now as car file was downloaded in the previous fetch
require.Eventually(t, func() bool {
err = csh.cs.FetchAndWriteCAR(reqID, rootcid, func(_ bstore.Blockstore) error {
return nil
})
fmt.Println("\n data downloaded after a cycle is", csh.ms.nDownloaded())
return err == nil
}, 50*time.Second, 200*time.Millisecond)

Expand Down
1 change: 1 addition & 0 deletions carstore/gateway_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (gw *GatewayReader) Read(p []byte) (int, error) {
}

func (gw *GatewayReader) Close() error {
fmt.Println("\n Recoding downloaded data", gw.n)
if err := gw.sapi.RecordDataDownloaded(gw.ctx, gw.n); err != nil {
log.Errorw("failed to record download stats", "err", err)
return err
Expand Down