Skip to content

Commit

Permalink
map: fix BenchmarkIterate
Browse files Browse the repository at this point in the history
CI fails on 5.4 with:

   map_test.go:2045: map batch api not supported (requires >= v5.6)

The benchmark also leaks m.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Dec 5, 2023
1 parent 9526bca commit 3968b9b
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,27 +1910,26 @@ func BenchmarkMarshaling(b *testing.B) {
}

func BenchmarkPerCPUMarshalling(b *testing.B) {
newMap := func(valueSize uint32) *Map {
m, err := NewMap(&MapSpec{
Type: PerCPUHash,
KeySize: 8,
ValueSize: valueSize,
MaxEntries: 1,
})
if err != nil {
b.Fatal(err)
}
return m
key := uint64(1)
val := make([]uint64, MustPossibleCPU())
for i := range val {
val[i] = uint64(i)
}

key := uint64(1)
val := []uint64{1, 2, 3, 4, 5, 6, 7, 8}
m, err := NewMap(&MapSpec{
Type: PerCPUHash,
KeySize: 8,
ValueSize: 8,
MaxEntries: 1,
})
if err != nil {
b.Fatal(err)
}

m := newMap(8)
b.Cleanup(func() { m.Close() })
if err := m.Put(key, val[0:]); err != nil {
b.Fatal(err)
}
b.Cleanup(func() { m.Close() })

b.Run("reflection", func(b *testing.B) {
b.ReportAllocs()
Expand Down Expand Up @@ -2041,9 +2040,9 @@ func BenchmarkIterate(b *testing.B) {
values[i] = uint64(i)
}

if _, err := m.BatchUpdate(keys, values, nil); err != nil {
b.Fatal(err)
}
_, err = m.BatchUpdate(keys, values, nil)
testutils.SkipIfNotSupported(b, err)
qt.Assert(b, err, qt.IsNil)

b.Run("MapIterator", func(b *testing.B) {
var k, v uint64
Expand Down

0 comments on commit 3968b9b

Please sign in to comment.