mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
Merge pull request #8694 from Roasbeef/fix-pkg-race
channeldb: fix race in TestPackager by removing global test var
This commit is contained in:
commit
b0463124d0
1 changed files with 34 additions and 21 deletions
|
@ -142,8 +142,31 @@ func checkPkgFilterEncodeDecode(t *testing.T, i uint16, f *channeldb.PkgFilter)
|
|||
|
||||
var (
|
||||
chanID = lnwire.NewChanIDFromOutPoint(wire.OutPoint{})
|
||||
)
|
||||
|
||||
adds = []channeldb.LogUpdate{
|
||||
func testSettleFails() []channeldb.LogUpdate {
|
||||
return []channeldb.LogUpdate{
|
||||
{
|
||||
LogIndex: 2,
|
||||
UpdateMsg: &lnwire.UpdateFulfillHTLC{
|
||||
ChanID: chanID,
|
||||
ID: 0,
|
||||
PaymentPreimage: [32]byte{0},
|
||||
},
|
||||
},
|
||||
{
|
||||
LogIndex: 3,
|
||||
UpdateMsg: &lnwire.UpdateFailHTLC{
|
||||
ChanID: chanID,
|
||||
ID: 1,
|
||||
Reason: []byte{},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func testAdds() []channeldb.LogUpdate {
|
||||
return []channeldb.LogUpdate{
|
||||
{
|
||||
LogIndex: 0,
|
||||
UpdateMsg: &lnwire.UpdateAddHTLC{
|
||||
|
@ -165,26 +188,7 @@ var (
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
settleFails = []channeldb.LogUpdate{
|
||||
{
|
||||
LogIndex: 2,
|
||||
UpdateMsg: &lnwire.UpdateFulfillHTLC{
|
||||
ChanID: chanID,
|
||||
ID: 0,
|
||||
PaymentPreimage: [32]byte{0},
|
||||
},
|
||||
},
|
||||
{
|
||||
LogIndex: 3,
|
||||
UpdateMsg: &lnwire.UpdateFailHTLC{
|
||||
ChanID: chanID,
|
||||
ID: 1,
|
||||
Reason: []byte{},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// TestPackagerEmptyFwdPkg checks that the state transitions exhibited by a
|
||||
// forwarding package that contains no adds, fails or settles. We expect that
|
||||
|
@ -273,6 +277,8 @@ func TestPackagerOnlyAdds(t *testing.T) {
|
|||
t.Fatalf("no forwarding packages should exist, found %d", len(fwdPkgs))
|
||||
}
|
||||
|
||||
adds := testAdds()
|
||||
|
||||
// Next, create and write a new forwarding package that only has add
|
||||
// htlcs.
|
||||
fwdPkg := channeldb.NewFwdPkg(shortChanID, 0, adds, nil)
|
||||
|
@ -377,6 +383,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
|
|||
|
||||
// Next, create and write a new forwarding package that only has add
|
||||
// htlcs.
|
||||
settleFails := testSettleFails()
|
||||
fwdPkg := channeldb.NewFwdPkg(shortChanID, 0, nil, settleFails)
|
||||
|
||||
nSettleFails := len(settleFails)
|
||||
|
@ -479,8 +486,11 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
|||
t.Fatalf("no forwarding packages should exist, found %d", len(fwdPkgs))
|
||||
}
|
||||
|
||||
adds := testAdds()
|
||||
|
||||
// Next, create and write a new forwarding package that only has add
|
||||
// htlcs.
|
||||
settleFails := testSettleFails()
|
||||
fwdPkg := channeldb.NewFwdPkg(shortChanID, 0, adds, settleFails)
|
||||
|
||||
nAdds := len(adds)
|
||||
|
@ -612,8 +622,11 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
|||
t.Fatalf("no forwarding packages should exist, found %d", len(fwdPkgs))
|
||||
}
|
||||
|
||||
adds := testAdds()
|
||||
|
||||
// Next, create and write a new forwarding package that has both add
|
||||
// and settle/fail htlcs.
|
||||
settleFails := testSettleFails()
|
||||
fwdPkg := channeldb.NewFwdPkg(shortChanID, 0, adds, settleFails)
|
||||
|
||||
nAdds := len(adds)
|
||||
|
|
Loading…
Add table
Reference in a new issue