mirror of
https://github.com/lightningnetwork/lnd.git
synced 2026-08-13 12:32:48 +02:00
sqldb: fix error comparison and refactor sqlite bench helpers
Replace direct `err != sql.ErrNoRows` comparison with `errors.Is` and extract the repeated fetch-and-check logic into a helper to reduce duplication across the sequential and concurrent benchmarks.
This commit is contained in:
parent
bd18a1e2d6
commit
cb36d0d977
1 changed files with 17 additions and 17 deletions
|
|
@ -15,6 +15,17 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// getInvoiceByHashForBench fetches an invoice by hash and reports any
|
||||
// error except sql.ErrNoRows (expected when the invoice doesn't exist).
|
||||
func getInvoiceByHashForBench(b *testing.B, store *SqliteStore,
|
||||
ctx context.Context, hash []byte) {
|
||||
|
||||
_, err := store.GetInvoiceByHash(ctx, hash)
|
||||
if err != nil {
|
||||
require.ErrorIs(b, err, sql.ErrNoRows)
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkSqliteMaxConns benchmarks sequential reads against a SQLite
|
||||
// database with varying MaxConnections settings.
|
||||
//
|
||||
|
|
@ -92,11 +103,7 @@ func BenchmarkSqliteMaxConns(b *testing.B) {
|
|||
for b.Loop() {
|
||||
hash := hashes[i%numInvoices]
|
||||
i++
|
||||
|
||||
_, err := store.GetInvoiceByHash(ctx, hash)
|
||||
if err != nil {
|
||||
require.ErrorIs(b, err, sql.ErrNoRows)
|
||||
}
|
||||
getInvoiceByHashForBench(b, store, ctx, hash)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -173,20 +180,13 @@ func BenchmarkSqliteMaxConnsConcurrentReads(b *testing.B) {
|
|||
wg.Add(goroutines)
|
||||
|
||||
for g := range goroutines {
|
||||
go func() {
|
||||
hash := hashes[g%numInvoices]
|
||||
go func(h []byte) {
|
||||
defer wg.Done()
|
||||
|
||||
hash := hashes[g%numInvoices]
|
||||
_, err := store.GetInvoiceByHash(
|
||||
ctx, hash,
|
||||
getInvoiceByHashForBench(
|
||||
b, store, ctx, h,
|
||||
)
|
||||
if err != nil &&
|
||||
err != sql.ErrNoRows {
|
||||
|
||||
b.Errorf("GetInvoice:"+
|
||||
" %v", err)
|
||||
}
|
||||
}()
|
||||
}(hash)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue