From 9ea7c24460ab136e5ac9776a8cb811850d90ebb1 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 28 Oct 2021 09:57:53 +0200 Subject: [PATCH] trie: error check in benchmark --- trie/difflayer_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/trie/difflayer_test.go b/trie/difflayer_test.go index 9f5d534e0f7f..f8c7a184e4c7 100644 --- a/trie/difflayer_test.go +++ b/trie/difflayer_test.go @@ -17,6 +17,7 @@ package trie import ( + "bytes" "math/rand" "testing" @@ -50,6 +51,7 @@ func emptyLayer() *diskLayer { func benchmarkSearch(b *testing.B, depth int) { var target []byte + var want []byte // First, we set up 128 diff layers, with 3K items each fill := func(parent snapshot, index int) *diffLayer { var nodes = make(map[string]*cachedNode) @@ -57,9 +59,11 @@ func benchmarkSearch(b *testing.B, depth int) { hash := randomHash() path := randomHash().Bytes() key := EncodeInternalKey(path, hash) - nodes[string(key)] = randomNode() + val := randomNode() + nodes[string(key)] = val if target == nil && depth == index { + want = val.rlp() target = append([]byte{}, key...) } } @@ -71,8 +75,18 @@ func benchmarkSearch(b *testing.B, depth int) { layer = fill(layer, i) } b.ResetTimer() + var ( + have []byte + err error + ) for i := 0; i < b.N; i++ { - layer.NodeBlob(target) + have, err = layer.NodeBlob(target) + if err != nil { + b.Fatal(err) + } + } + if !bytes.Equal(have, want) { + b.Fatalf("have %x want %x", have, want) } }