Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using unexported constants in tests #485

Open
wants to merge 5 commits into
base: fxamacker/avoid-accessing-SlabID-fields-in-tests
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions array_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
// setup
for i := 0; i < initialArraySize; i++ {
v := RandomValue(r)
storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)
totalRawDataSize += storable.ByteSize()
err = array.Append(v)
Expand All @@ -107,7 +107,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
for i := 0; i < numberOfElements; i++ {
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down Expand Up @@ -143,7 +143,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
ind := r.Intn(int(array.Count()))
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down Expand Up @@ -217,7 +217,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
for i := 0; i < initialArraySize; i++ {
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand All @@ -239,7 +239,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
case 1: // insert
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), maxInlineArrayElementSize)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)

totalRawDataSize += storable.ByteSize()
Expand Down
38 changes: 19 additions & 19 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ func TestArraySetRandomValues(t *testing.T) {

for i := uint64(0); i < arraySize; i++ {
oldValue := values[i]
newValue := randomValue(r, int(maxInlineArrayElementSize))
newValue := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = newValue

existingStorable, err := array.Set(i, newValue)
Expand Down Expand Up @@ -2490,7 +2490,7 @@ func TestArrayInsertRandomValues(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[arraySize-i-1] = v

err := array.Insert(0, v)
Expand All @@ -2515,7 +2515,7 @@ func TestArrayInsertRandomValues(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Insert(i, v)
Expand All @@ -2541,7 +2541,7 @@ func TestArrayInsertRandomValues(t *testing.T) {
values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
k := r.Intn(int(i) + 1)
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

copy(values[k+1:], values[k:])
values[k] = v
Expand Down Expand Up @@ -2573,7 +2573,7 @@ func TestArrayRemoveRandomValues(t *testing.T) {
values := make([]Value, arraySize)
// Insert n random values into array
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Insert(i, v)
Expand Down Expand Up @@ -2640,15 +2640,15 @@ func testArrayAppendSetInsertRemoveRandomValues(
switch nextOp {

case ArrayAppendOp:
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values = append(values, v)

err := array.Append(v)
require.NoError(t, err)

case ArraySetOp:
k := r.Intn(int(array.Count()))
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

oldV := values[k]

Expand All @@ -2668,7 +2668,7 @@ func testArrayAppendSetInsertRemoveRandomValues(

case ArrayInsertOp:
k := r.Intn(int(array.Count() + 1))
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))

if k == int(array.Count()) {
values = append(values, v)
Expand Down Expand Up @@ -4457,7 +4457,7 @@ func TestArrayStringElement(t *testing.T) {

r := newRand(t)

stringSize := int(maxInlineArrayElementSize - 3)
stringSize := int(MaxInlineArrayElementSize() - 3)

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
Expand Down Expand Up @@ -4490,7 +4490,7 @@ func TestArrayStringElement(t *testing.T) {

r := newRand(t)

stringSize := int(maxInlineArrayElementSize + 512)
stringSize := int(MaxInlineArrayElementSize() + 512)

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
Expand Down Expand Up @@ -4787,7 +4787,7 @@ func TestArrayFromBatchData(t *testing.T) {
var values []Value
var v Value

v = NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize-2)))
v = NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()-2)))
values = append(values, v)

err = array.Insert(0, v)
Expand Down Expand Up @@ -4843,7 +4843,7 @@ func TestArrayFromBatchData(t *testing.T) {
require.NoError(t, err)
}

v = NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize-2)))
v = NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()-2)))
values = append(values, nil)
copy(values[25+1:], values[25:])
values[25] = v
Expand Down Expand Up @@ -4890,7 +4890,7 @@ func TestArrayFromBatchData(t *testing.T) {

values := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
v := randomValue(r, int(maxInlineArrayElementSize))
v := randomValue(r, int(MaxInlineArrayElementSize()))
values[i] = v

err := array.Append(v)
Expand Down Expand Up @@ -4939,17 +4939,17 @@ func TestArrayFromBatchData(t *testing.T) {
var values []Value
var v Value

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)

v = NewStringValue(randStr(r, int(maxInlineArrayElementSize-2)))
v = NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-2)))
values = append(values, v)
err = array.Append(v)
require.NoError(t, err)
Expand Down Expand Up @@ -5016,7 +5016,7 @@ func TestArrayMaxInlineElement(t *testing.T) {
var values []Value
for i := 0; i < 2; i++ {
// String length is MaxInlineArrayElementSize - 3 to account for string encoding overhead.
v := NewStringValue(randStr(r, int(maxInlineArrayElementSize-3)))
v := NewStringValue(randStr(r, int(MaxInlineArrayElementSize()-3)))
values = append(values, v)

err = array.Append(v)
Expand All @@ -5028,7 +5028,7 @@ func TestArrayMaxInlineElement(t *testing.T) {
// Size of root data slab with two elements of max inlined size is target slab size minus
// slab id size (next slab id is omitted in root slab), and minus 1 byte
// (for rounding when computing max inline array element size).
require.Equal(t, targetThreshold-SlabIDLength-1, uint64(array.root.Header().size))
require.Equal(t, TargetSlabSize()-SlabIDLength-1, uint64(array.root.Header().size))

testArray(t, storage, typeInfo, address, array, values, false)
}
Expand Down Expand Up @@ -5139,7 +5139,7 @@ func TestArraySlabDump(t *testing.T) {
array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)

err = array.Append(NewStringValue(strings.Repeat("a", int(maxInlineArrayElementSize))))
err = array.Append(NewStringValue(strings.Repeat("a", int(MaxInlineArrayElementSize()))))
require.NoError(t, err)

want := []string{
Expand Down
5 changes: 5 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ var (
GetCBOREncMode = (*PersistentSlabStorage).getCBOREncMode
GetCBORDecMode = (*PersistentSlabStorage).getCBORDecMode
)

// Exported function of slab size settings for testing.
var (
TargetSlabSize = targetSlabSize
)
Loading
Loading