tlv/bench_test: check for errors in benchmarks
This commit is contained in:
parent
055db6b9ac
commit
7cd78afd1a
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/blob"
|
"github.com/lightningnetwork/lnd/watchtower/blob"
|
||||||
"github.com/lightningnetwork/lnd/watchtower/wtwire"
|
"github.com/lightningnetwork/lnd/watchtower/wtwire"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateSessionTLV mirrors the wtwire.CreateSession message, but uses TLV for
|
// 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++ {
|
for i := 0; i < t.N; i++ {
|
||||||
err = m.Encode(ioutil.Discard, 0)
|
err = m.Encode(ioutil.Discard, 0)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession.
|
// BenchmarkEncodeCreateSessionTLV benchmarks encoding of the TLV CreateSession.
|
||||||
@ -118,7 +119,7 @@ func BenchmarkEncodeCreateSessionTLV(t *testing.B) {
|
|||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
err = m.Encode(ioutil.Discard)
|
err = m.Encode(ioutil.Discard)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV
|
// BenchmarkDecodeCreateSession benchmarks encoding of the non-TLV
|
||||||
@ -127,18 +128,19 @@ func BenchmarkDecodeCreateSession(t *testing.B) {
|
|||||||
m := &wtwire.CreateSession{}
|
m := &wtwire.CreateSession{}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
m.Encode(&b, 0)
|
err := m.Encode(&b, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
r := bytes.NewReader(b.Bytes())
|
r := bytes.NewReader(b.Bytes())
|
||||||
|
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
t.ResetTimer()
|
t.ResetTimer()
|
||||||
|
|
||||||
var err error
|
|
||||||
for i := 0; i < t.N; i++ {
|
for i := 0; i < t.N; i++ {
|
||||||
r.Seek(0, 0)
|
r.Seek(0, 0)
|
||||||
err = m.Decode(r, 0)
|
err = m.Decode(r, 0)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession.
|
// BenchmarkDecodeCreateSessionTLV benchmarks decoding of the TLV CreateSession.
|
||||||
@ -146,8 +148,9 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
|
|||||||
m := NewCreateSessionTLV()
|
m := NewCreateSessionTLV()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
var err error
|
err := m.Encode(&b)
|
||||||
m.Encode(&b)
|
require.NoError(t, err)
|
||||||
|
|
||||||
r := bytes.NewReader(b.Bytes())
|
r := bytes.NewReader(b.Bytes())
|
||||||
|
|
||||||
t.ReportAllocs()
|
t.ReportAllocs()
|
||||||
@ -157,5 +160,5 @@ func BenchmarkDecodeCreateSessionTLV(t *testing.B) {
|
|||||||
r.Seek(0, 0)
|
r.Seek(0, 0)
|
||||||
err = m.Decode(r)
|
err = m.Decode(r)
|
||||||
}
|
}
|
||||||
_ = err
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user