Skip to content

Commit

Permalink
add black box testing for file
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed May 29, 2024
1 parent 1e7a637 commit 76c2dc4
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions share/store/file/testing.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//nolint:unused // this directive will be removed in next PR, where benchmarks will be used
package file

import (
"context"
"fmt"
"github.com/celestiaorg/celestia-node/share/eds/edstest"
"github.com/celestiaorg/celestia-node/share/sharetest"
"github.com/stretchr/testify/require"
mrand "math/rand"
"strconv"
"sync"
"testing"

"github.com/stretchr/testify/require"

"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/eds/edstest"
"github.com/celestiaorg/celestia-node/share/sharetest"
)

type createFile func(eds *rsmt2d.ExtendedDataSquare) EdsFile
Expand All @@ -30,7 +32,7 @@ func testFileShare(t *testing.T, createFile createFile, odsSize int) {
t.Run("single thread", func(t *testing.T) {
for x := 0; x < width; x++ {
for y := 0; y < width; y++ {
testShare(t, fl, eds, dah, x, y)
testShare(t, fl, dah, x, y)
}
}
})
Expand All @@ -42,7 +44,7 @@ func testFileShare(t *testing.T, createFile createFile, odsSize int) {
wg.Add(1)
go func(x, y int) {
defer wg.Done()
testShare(t, fl, eds, dah, x, y)
testShare(t, fl, dah, x, y)
}(x, y)
}
}
Expand All @@ -52,9 +54,9 @@ func testFileShare(t *testing.T, createFile createFile, odsSize int) {

func testShare(t *testing.T,
fl EdsFile,
eds *rsmt2d.ExtendedDataSquare,
dah *share.Root,
x, y int) {
x, y int,
) {
shr, err := fl.Share(context.TODO(), x, y)
require.NoError(t, err)

Expand All @@ -66,7 +68,7 @@ func testFileData(t *testing.T, createFile createFile, size int) {
t.Run("included", func(t *testing.T) {
// generate EDS with random data and some Shares with the same namespace
namespace := sharetest.RandV0Namespace()
amount := mrand.Intn(size*size-1) + 1
amount := mrand.Intn(size*size-1) + 1 //nolint:gosec // it is fine to use weak random in test
eds, dah := edstest.RandEDSWithNamespace(t, namespace, amount, size)
f := createFile(eds)
testData(t, f, namespace, dah)
Expand Down Expand Up @@ -187,7 +189,7 @@ func benchGetShareFromFile(b *testing.B, newFile func(size int) EdsFile, minSize
x, y := q.coordinates(f.Size())
// warm up cache
_, err := f.Share(context.TODO(), x, y)
require.NoError(b, err)
require.NoError(b, err, q.String())

b.ResetTimer()
for i := 0; i < b.N; i++ {
Expand All @@ -196,15 +198,12 @@ func benchGetShareFromFile(b *testing.B, newFile func(size int) EdsFile, minSize
}
})
}

}
}

type quadrant int

var (
quadrants = []quadrant{1, 2, 3, 4}
)
var quadrants = []quadrant{1, 2, 3, 4}

func (q quadrant) String() string {
return strconv.Itoa(int(q))
Expand Down

0 comments on commit 76c2dc4

Please sign in to comment.