Skip to content

Commit

Permalink
improve index naming
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed May 29, 2024
1 parent 76c2dc4 commit 482eec1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions share/store/file/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ func testFileShare(t *testing.T, createFile createFile, odsSize int) {

width := int(eds.Width())
t.Run("single thread", func(t *testing.T) {
for x := 0; x < width; x++ {
for y := 0; y < width; y++ {
testShare(t, fl, dah, x, y)
for rowIdx := 0; rowIdx < width; rowIdx++ {
for colIdx := 0; colIdx < width; colIdx++ {
testShare(t, fl, dah, colIdx, rowIdx)
}
}
})

t.Run("parallel", func(t *testing.T) {
wg := sync.WaitGroup{}
for y := 0; y < width; y++ {
for x := 0; x < width; x++ {
for rowIdx := 0; rowIdx < width; rowIdx++ {
for colIdx := 0; colIdx < width; colIdx++ {
wg.Add(1)
go func(x, y int) {
defer wg.Done()
testShare(t, fl, dah, x, y)
}(x, y)
}(colIdx, rowIdx)
}
}
wg.Wait()
Expand All @@ -68,6 +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()
// select random amount of shares, but not less than 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)
Expand All @@ -80,12 +81,13 @@ func testFileData(t *testing.T, createFile createFile, size int) {
dah, err := share.NewRoot(eds)
require.NoError(t, err)

// select namespace that within the range of root namespaces, but is not included
maxNs := nmt.MaxNamespace(dah.RowRoots[(len(dah.RowRoots))/2-1], share.NamespaceSize)
targetNs, err := share.Namespace(maxNs).AddInt(-1)
missingNs, err := share.Namespace(maxNs).AddInt(-1)
require.NoError(t, err)

f := createFile(eds)
testData(t, f, targetNs, dah)
testData(t, f, missingNs, dah)
})
}

Expand All @@ -106,16 +108,16 @@ func testFileAxisHalf(t *testing.T, createFile createFile, odsSize int) {

t.Run("single thread", func(t *testing.T) {
for _, axisType := range []rsmt2d.Axis{rsmt2d.Col, rsmt2d.Row} {
for i := 0; i < int(eds.Width()); i++ {
half, err := fl.AxisHalf(context.Background(), axisType, i)
for axisIdx := 0; axisIdx < int(eds.Width()); axisIdx++ {
half, err := fl.AxisHalf(context.Background(), axisType, axisIdx)
require.NoError(t, err)
require.Len(t, half.Shares, odsSize)

var expected []share.Share
if half.IsParity {
expected = getAxis(eds, axisType, i)[odsSize:]
expected = getAxis(eds, axisType, axisIdx)[odsSize:]
} else {
expected = getAxis(eds, axisType, i)[:odsSize]
expected = getAxis(eds, axisType, axisIdx)[:odsSize]
}

require.Equal(t, expected, half.Shares)
Expand Down

0 comments on commit 482eec1

Please sign in to comment.