tlv/bench_test: check for errors in benchmarks

This commit is contained in:
Conner Fromknecht 2021-03-04 10:00:45 -08:00
parent 055db6b9ac
commit 7cd78afd1a
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

View File

@ -10,6 +10,7 @@ import (
"github.com/lightningnetwork/lnd/tlv"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtwire"
"github.com/stretchr/testify/require"
)
// CreateSessionTLV mirrors the wtwire.CreateSession message, but uses TLV for
@ -104,7 +105,7 @@ func BenchmarkEncodeCreateSession(t *testing.B) {
for i := 0; i < t.N; i++ {
err = m.Encode(ioutil.Discard, 0)
}
_ = err
require.NoError(t, err)
}
// BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession.
@ -118,7 +119,7 @@ func BenchmarkEncodeCreateSessionTLV(t *testing.B) {
for i := 0; i < t.N; i++ {
err = m.Encode(ioutil.Discard)
}
_ = err
require.NoError(t, err)
}
// BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV
@ -127,18 +128,19 @@ func BenchmarkDecodeCreateSession(t *testing.B) {
m := &wtwire.CreateSession{}
var b bytes.Buffer
m.Encode(&b, 0)
err := m.Encode(&b, 0)
require.NoError(t, err)
r := bytes.NewReader(b.Bytes())
t.ReportAllocs()
t.ResetTimer()
var err error
for i := 0; i < t.N; i++ {
r.Seek(0, 0)
err = m.Decode(r, 0)
}
_ = err
require.NoError(t, err)
}
// BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession.
@ -146,8 +148,9 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
m := NewCreateSessionTLV()
var b bytes.Buffer
var err error
m.Encode(&b)
err := m.Encode(&b)
require.NoError(t, err)
r := bytes.NewReader(b.Bytes())
t.ReportAllocs()
@ -157,5 +160,5 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
r.Seek(0, 0)
err = m.Decode(r)
}
_ = err
require.NoError(t, err)
}