Skip to content

Commit

Permalink
linters
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikspatil024 committed Sep 29, 2022
1 parent 5fcb024 commit 77189d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
32 changes: 25 additions & 7 deletions core/blockstm/mvhashmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func getCommonAddress(i int) common.Address {
}

func TestHelperFunctions(t *testing.T) {
t.Parallel()

ap1 := NewAddressKey(getCommonAddress(1))
ap2 := NewAddressKey(getCommonAddress(2))

Expand Down Expand Up @@ -51,6 +53,8 @@ func TestHelperFunctions(t *testing.T) {
}

func TestFlushMVWrite(t *testing.T) {
t.Parallel()

ap1 := NewAddressKey(getCommonAddress(1))
ap2 := NewAddressKey(getCommonAddress(2))

Expand Down Expand Up @@ -110,13 +114,10 @@ func TestFlushMVWrite(t *testing.T) {
require.Equal(t, 0, res.Status())
}

// TODO - add TestValidateVersion after making it parallel (maybe benchmark it)
// func TestValidateVersion(t *testing.T) {

// }

// TODO - handle panic
func TestLowerIncarnation(t *testing.T) {
t.Parallel()

ap1 := NewAddressKey(getCommonAddress(1))

mvh := MakeMVHashMap()
Expand All @@ -126,11 +127,11 @@ func TestLowerIncarnation(t *testing.T) {
mvh.Write(ap1, Version{1, 2}, valueFor(1, 2))
mvh.Write(ap1, Version{0, 5}, valueFor(0, 5))
mvh.Write(ap1, Version{1, 5}, valueFor(1, 5))
// will fail (panic) as Version{0 4} has lower incarnation than Version{0 5}
// mvh.Write(ap1, Version{0, 4}, valueFor(0, 4))
}

func TestMarkEstimate(t *testing.T) {
t.Parallel()

ap1 := NewAddressKey(getCommonAddress(1))

mvh := MakeMVHashMap()
Expand All @@ -141,6 +142,8 @@ func TestMarkEstimate(t *testing.T) {
}

func TestMVHashMapBasics(t *testing.T) {
t.Parallel()

// memory locations
ap1 := NewAddressKey(getCommonAddress(1))
ap2 := NewAddressKey(getCommonAddress(2))
Expand Down Expand Up @@ -247,6 +250,7 @@ func BenchmarkWriteTimeSameLocationDifferentTxIdx(b *testing.B) {
}

b.ResetTimer()

for i := 0; i < b.N; i++ {
mvh2.Write(ap2, Version{randInts[i], 1}, valueFor(randInts[i], 1))
}
Expand All @@ -256,6 +260,7 @@ func BenchmarkReadTimeSameLocationDifferentTxIdx(b *testing.B) {
mvh2 := MakeMVHashMap()
ap2 := NewAddressKey(getCommonAddress(2))
txIdxSlice := []int{}

for i := 0; i < b.N; i++ {
txIdx := rand.Intn(1000000000000000)
txIdxSlice = append(txIdxSlice, txIdx)
Expand All @@ -269,6 +274,7 @@ func BenchmarkReadTimeSameLocationDifferentTxIdx(b *testing.B) {
}

func TestTimeComplexity(t *testing.T) {
t.Parallel()

// for 1000000 read and write with no dependency at different memory location
mvh1 := MakeMVHashMap()
Expand All @@ -281,6 +287,7 @@ func TestTimeComplexity(t *testing.T) {
// for 1000000 read and write with dependency at same memory location
mvh2 := MakeMVHashMap()
ap2 := NewAddressKey(getCommonAddress(2))

for i := 0; i < 1000000; i++ {
mvh2.Write(ap2, Version{i, 1}, valueFor(i, 1))
mvh2.Read(ap2, i)
Expand All @@ -289,22 +296,30 @@ func TestTimeComplexity(t *testing.T) {
}

func TestWriteTimeSameLocationDifferentTxnIdx(t *testing.T) {
t.Parallel()

mvh1 := MakeMVHashMap()
ap1 := NewAddressKey(getCommonAddress(1))

for i := 0; i < 1000000; i++ {
mvh1.Write(ap1, Version{i, 1}, valueFor(i, 1))
}
}

func TestWriteTimeSameLocationSameTxnIdx(t *testing.T) {
t.Parallel()

mvh1 := MakeMVHashMap()
ap1 := NewAddressKey(getCommonAddress(1))

for i := 0; i < 1000000; i++ {
mvh1.Write(ap1, Version{1, i}, valueFor(i, 1))
}
}

func TestWriteTimeDifferentLocation(t *testing.T) {
t.Parallel()

mvh1 := MakeMVHashMap()
for i := 0; i < 1000000; i++ {
ap1 := NewAddressKey(getCommonAddress(i))
Expand All @@ -313,8 +328,11 @@ func TestWriteTimeDifferentLocation(t *testing.T) {
}

func TestReadTimeSameLocation(t *testing.T) {
t.Parallel()

mvh1 := MakeMVHashMap()
ap1 := NewAddressKey(getCommonAddress(1))

mvh1.Write(ap1, Version{1, 1}, valueFor(1, 1))
for i := 0; i < 1000000; i++ {
mvh1.Read(ap1, 2)
Expand Down
7 changes: 4 additions & 3 deletions core/blockstm/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

func TestStatusBasics(t *testing.T) {

s := makeStatusManager(10)

x := s.takeNextPending()
Expand Down Expand Up @@ -44,18 +43,18 @@ func TestStatusBasics(t *testing.T) {

exp := []int{1, 2}
require.Equal(t, exp, s.getRevalidationRange(1))

}

func TestMaxComplete(t *testing.T) {

s := makeStatusManager(10)

for {
tx := s.takeNextPending()

if tx == -1 {
break
}

if tx != 7 {
s.markComplete(tx)
}
Expand All @@ -64,8 +63,10 @@ func TestMaxComplete(t *testing.T) {
require.Equal(t, 6, s.maxAllComplete())

s2 := makeStatusManager(10)

for {
tx := s2.takeNextPending()

if tx == -1 {
break
}
Expand Down

0 comments on commit 77189d8

Please sign in to comment.