-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Reapply #8644 #9242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reapply #8644 #9242
Changes from all commits
bf16b54
3cebd37
f3bb709
a0e5a14
211dd21
c29fb81
c01dcc2
780c271
68e9aea
c5d0976
53d34d2
c9d217b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package batch | ||
|
|
||
| import ( | ||
| "errors" | ||
| "path/filepath" | ||
| "sync" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/btcsuite/btcwallet/walletdb" | ||
| "github.com/lightningnetwork/lnd/kvdb" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestRetry(t *testing.T) { | ||
| dbDir := t.TempDir() | ||
|
|
||
| dbName := filepath.Join(dbDir, "weks.db") | ||
| db, err := walletdb.Create( | ||
| "bdb", dbName, true, kvdb.DefaultDBTimeout, | ||
| ) | ||
| if err != nil { | ||
| t.Fatalf("unable to create walletdb: %v", err) | ||
| } | ||
| t.Cleanup(func() { | ||
| db.Close() | ||
| }) | ||
|
|
||
| var ( | ||
| mu sync.Mutex | ||
| called int | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used a mutex because the underlying
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a nit-picking, so nvm |
||
| ) | ||
| sched := NewTimeScheduler(db, &mu, time.Second) | ||
|
|
||
| // First, we construct a request that should retry individually and | ||
| // execute it non-lazily. It should still return the error the second | ||
| // time. | ||
| req := &Request{ | ||
| Update: func(tx kvdb.RwTx) error { | ||
| called++ | ||
|
|
||
| return errors.New("test") | ||
| }, | ||
| } | ||
| err = sched.Execute(req) | ||
|
|
||
| // Check and reset the called counter. | ||
| mu.Lock() | ||
| require.Equal(t, 2, called) | ||
| called = 0 | ||
| mu.Unlock() | ||
|
|
||
| require.ErrorContains(t, err, "test") | ||
|
|
||
| // Now, we construct a request that should NOT retry because it returns | ||
| // a serialization error, which should cause the underlying postgres | ||
| // transaction to retry. Since we aren't using postgres, this will | ||
| // cause the transaction to not be retried at all. | ||
| req = &Request{ | ||
| Update: func(tx kvdb.RwTx) error { | ||
| called++ | ||
|
|
||
| return errors.New("could not serialize access") | ||
| }, | ||
| } | ||
| err = sched.Execute(req) | ||
|
|
||
| // Check the called counter. | ||
| mu.Lock() | ||
| require.Equal(t, 1, called) | ||
| mu.Unlock() | ||
|
|
||
| require.ErrorContains(t, err, "could not serialize access") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ require ( | |
| github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 | ||
| github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c | ||
| github.com/btcsuite/btclog/v2 v2.0.0 | ||
| github.com/btcsuite/btcwallet v0.16.10-0.20241113134707-b4ff60753aaa | ||
| github.com/btcsuite/btcwallet v0.16.10-0.20241127094224-93c858b2ad63 | ||
| github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 | ||
| github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 | ||
| github.com/btcsuite/btcwallet/walletdb v1.4.4 | ||
|
|
@@ -203,6 +203,12 @@ replace github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.11 | |
| // https://deps.dev/advisory/OSV/GO-2021-0053?from=%2Fgo%2Fgithub.com%252Fgogo%252Fprotobuf%2Fv1.3.1 | ||
| replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 | ||
|
|
||
| // Use local kvdb package until new version is tagged. | ||
|
aakselrod marked this conversation as resolved.
|
||
| replace github.com/lightningnetwork/lnd/kvdb => ./kvdb | ||
|
aakselrod marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we merge the changes to |
||
|
|
||
| // Use local sqldb package until new version is tagged. | ||
| replace github.com/lightningnetwork/lnd/sqldb => ./sqldb | ||
|
|
||
| // We want to format raw bytes as hex instead of base64. The forked version | ||
| // allows us to specify that as an option. | ||
| replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ require ( | |
| go.etcd.io/etcd/client/v3 v3.5.7 | ||
| go.etcd.io/etcd/server/v3 v3.5.7 | ||
| golang.org/x/net v0.22.0 | ||
| modernc.org/sqlite v1.29.8 | ||
| modernc.org/sqlite v1.29.10 | ||
| ) | ||
|
|
||
| require ( | ||
|
|
@@ -59,6 +59,7 @@ require ( | |
| github.com/jackc/pgproto3/v2 v2.3.3 // indirect | ||
| github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
| github.com/jackc/pgtype v1.14.0 // indirect | ||
| github.com/jackc/pgx/v5 v5.3.1 // indirect | ||
| github.com/jonboulle/clockwork v0.2.2 // indirect | ||
| github.com/json-iterator/go v1.1.11 // indirect | ||
| github.com/lib/pq v1.10.9 // indirect | ||
|
|
@@ -135,6 +136,9 @@ replace github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt v3.2.1+incompat | |
| // This replace is for https://github.com/advisories/GHSA-25xm-hr59-7c27 | ||
| replace github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.11 | ||
|
|
||
| // Use local sqldb package until new version is tagged. | ||
| replace github.com/lightningnetwork/lnd/sqldb => ../sqldb | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving comment so we remember the replace is here. |
||
|
|
||
| // This replace is for | ||
| // https://deps.dev/advisory/OSV/GO-2021-0053?from=%2Fgo%2Fgithub.com%252Fgogo%252Fprotobuf%2Fv1.3.1 | ||
| replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.