mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
invoices: ensure synchronous access to NewTestSqliteDB
Add a temporary mutex around the calls to sqldb.NewTestSqliteDB to ensure that only a single thread can access it at a time. This is a temporary work around that can be removed once this race condition in the sqlite repo has been resolved: https://gitlab.com/cznic/sqlite/-/issues/180
This commit is contained in:
parent
b4e4e9447a
commit
d4f63662c1
@ -6,6 +6,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/quick"
|
"testing/quick"
|
||||||
"time"
|
"time"
|
||||||
@ -23,6 +24,12 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// sqliteConstructorMu is used to ensure that only one thread can call the
|
||||||
|
// sqldb.NewTestSqliteDB constructor at a time. This is a temporary workaround
|
||||||
|
// that can be removed once this race condition in the sqlite repo is resolved:
|
||||||
|
// https://gitlab.com/cznic/sqlite/-/issues/180
|
||||||
|
var sqliteConstructorMu sync.Mutex
|
||||||
|
|
||||||
// TestInvoiceRegistry is a master test which encompasses all tests using an
|
// TestInvoiceRegistry is a master test which encompasses all tests using an
|
||||||
// InvoiceDB instance. The purpose of this test is to be able to run all tests
|
// InvoiceDB instance. The purpose of this test is to be able to run all tests
|
||||||
// with a custom DB instance, so that we can test the same logic with different
|
// with a custom DB instance, so that we can test the same logic with different
|
||||||
@ -130,7 +137,9 @@ func TestInvoiceRegistry(t *testing.T) {
|
|||||||
|
|
||||||
var db *sqldb.BaseDB
|
var db *sqldb.BaseDB
|
||||||
if sqlite {
|
if sqlite {
|
||||||
|
sqliteConstructorMu.Lock()
|
||||||
db = sqldb.NewTestSqliteDB(t).BaseDB
|
db = sqldb.NewTestSqliteDB(t).BaseDB
|
||||||
|
sqliteConstructorMu.Unlock()
|
||||||
} else {
|
} else {
|
||||||
db = sqldb.NewTestPostgresDB(t, pgFixture).BaseDB
|
db = sqldb.NewTestPostgresDB(t, pgFixture).BaseDB
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,9 @@ func TestInvoices(t *testing.T) {
|
|||||||
makeSQLDB := func(t *testing.T, sqlite bool) invpkg.InvoiceDB {
|
makeSQLDB := func(t *testing.T, sqlite bool) invpkg.InvoiceDB {
|
||||||
var db *sqldb.BaseDB
|
var db *sqldb.BaseDB
|
||||||
if sqlite {
|
if sqlite {
|
||||||
|
sqliteConstructorMu.Lock()
|
||||||
db = sqldb.NewTestSqliteDB(t).BaseDB
|
db = sqldb.NewTestSqliteDB(t).BaseDB
|
||||||
|
sqliteConstructorMu.Unlock()
|
||||||
} else {
|
} else {
|
||||||
db = sqldb.NewTestPostgresDB(t, pgFixture).BaseDB
|
db = sqldb.NewTestPostgresDB(t, pgFixture).BaseDB
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user