htlcswitch/test_utils: set BatchTicker mock and BatchSize
This commit adds the mockTicker and BatchSize to the link config. It also exits the goroutines draining the HtlcUpdates gracefully.
This commit is contained in:
parent
f83f47541d
commit
ab75cd3a4d
@ -437,17 +437,21 @@ type threeHopNetwork struct {
|
|||||||
aliceServer *mockServer
|
aliceServer *mockServer
|
||||||
aliceChannelLink *channelLink
|
aliceChannelLink *channelLink
|
||||||
aliceBlockEpoch chan *chainntnfs.BlockEpoch
|
aliceBlockEpoch chan *chainntnfs.BlockEpoch
|
||||||
|
aliceTicker *time.Ticker
|
||||||
|
|
||||||
firstBobChannelLink *channelLink
|
firstBobChannelLink *channelLink
|
||||||
bobFirstBlockEpoch chan *chainntnfs.BlockEpoch
|
bobFirstBlockEpoch chan *chainntnfs.BlockEpoch
|
||||||
|
firstBobTicker *time.Ticker
|
||||||
|
|
||||||
bobServer *mockServer
|
bobServer *mockServer
|
||||||
secondBobChannelLink *channelLink
|
secondBobChannelLink *channelLink
|
||||||
bobSecondBlockEpoch chan *chainntnfs.BlockEpoch
|
bobSecondBlockEpoch chan *chainntnfs.BlockEpoch
|
||||||
|
secondBobTicker *time.Ticker
|
||||||
|
|
||||||
carolChannelLink *channelLink
|
carolChannelLink *channelLink
|
||||||
carolServer *mockServer
|
carolServer *mockServer
|
||||||
carolBlockEpoch chan *chainntnfs.BlockEpoch
|
carolBlockEpoch chan *chainntnfs.BlockEpoch
|
||||||
|
carolTicker *time.Ticker
|
||||||
|
|
||||||
feeEstimator *mockFeeEstimator
|
feeEstimator *mockFeeEstimator
|
||||||
|
|
||||||
@ -625,6 +629,11 @@ func (n *threeHopNetwork) stop() {
|
|||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
n.aliceTicker.Stop()
|
||||||
|
n.firstBobTicker.Stop()
|
||||||
|
n.secondBobTicker.Stop()
|
||||||
|
n.carolTicker.Stop()
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
@ -743,6 +752,7 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
aliceTicker := time.NewTicker(50 * time.Millisecond)
|
||||||
aliceChannelLink := NewChannelLink(
|
aliceChannelLink := NewChannelLink(
|
||||||
ChannelLinkConfig{
|
ChannelLinkConfig{
|
||||||
FwrdingPolicy: globalPolicy,
|
FwrdingPolicy: globalPolicy,
|
||||||
@ -763,6 +773,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
},
|
},
|
||||||
ChainEvents: &contractcourt.ChainEventSubscription{},
|
ChainEvents: &contractcourt.ChainEventSubscription{},
|
||||||
SyncStates: true,
|
SyncStates: true,
|
||||||
|
BatchTicker: &mockTicker{aliceTicker.C},
|
||||||
|
BatchSize: 10,
|
||||||
},
|
},
|
||||||
aliceChannel,
|
aliceChannel,
|
||||||
startingHeight,
|
startingHeight,
|
||||||
@ -772,7 +784,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-aliceChannelLink.(*channelLink).htlcUpdates
|
select {
|
||||||
|
case <-aliceChannelLink.(*channelLink).htlcUpdates:
|
||||||
|
case <-aliceChannelLink.(*channelLink).quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -782,6 +798,7 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
firstBobTicker := time.NewTicker(50 * time.Millisecond)
|
||||||
firstBobChannelLink := NewChannelLink(
|
firstBobChannelLink := NewChannelLink(
|
||||||
ChannelLinkConfig{
|
ChannelLinkConfig{
|
||||||
FwrdingPolicy: globalPolicy,
|
FwrdingPolicy: globalPolicy,
|
||||||
@ -802,6 +819,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
},
|
},
|
||||||
ChainEvents: &contractcourt.ChainEventSubscription{},
|
ChainEvents: &contractcourt.ChainEventSubscription{},
|
||||||
SyncStates: true,
|
SyncStates: true,
|
||||||
|
BatchTicker: &mockTicker{firstBobTicker.C},
|
||||||
|
BatchSize: 10,
|
||||||
},
|
},
|
||||||
firstBobChannel,
|
firstBobChannel,
|
||||||
startingHeight,
|
startingHeight,
|
||||||
@ -811,7 +830,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-firstBobChannelLink.(*channelLink).htlcUpdates
|
select {
|
||||||
|
case <-firstBobChannelLink.(*channelLink).htlcUpdates:
|
||||||
|
case <-firstBobChannelLink.(*channelLink).quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -821,6 +844,7 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
secondBobTicker := time.NewTicker(50 * time.Millisecond)
|
||||||
secondBobChannelLink := NewChannelLink(
|
secondBobChannelLink := NewChannelLink(
|
||||||
ChannelLinkConfig{
|
ChannelLinkConfig{
|
||||||
FwrdingPolicy: globalPolicy,
|
FwrdingPolicy: globalPolicy,
|
||||||
@ -841,6 +865,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
},
|
},
|
||||||
ChainEvents: &contractcourt.ChainEventSubscription{},
|
ChainEvents: &contractcourt.ChainEventSubscription{},
|
||||||
SyncStates: true,
|
SyncStates: true,
|
||||||
|
BatchTicker: &mockTicker{secondBobTicker.C},
|
||||||
|
BatchSize: 10,
|
||||||
},
|
},
|
||||||
secondBobChannel,
|
secondBobChannel,
|
||||||
startingHeight,
|
startingHeight,
|
||||||
@ -850,7 +876,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-secondBobChannelLink.(*channelLink).htlcUpdates
|
select {
|
||||||
|
case <-secondBobChannelLink.(*channelLink).htlcUpdates:
|
||||||
|
case <-secondBobChannelLink.(*channelLink).quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -860,6 +890,7 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
carolTicker := time.NewTicker(50 * time.Millisecond)
|
||||||
carolChannelLink := NewChannelLink(
|
carolChannelLink := NewChannelLink(
|
||||||
ChannelLinkConfig{
|
ChannelLinkConfig{
|
||||||
FwrdingPolicy: globalPolicy,
|
FwrdingPolicy: globalPolicy,
|
||||||
@ -880,6 +911,8 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
},
|
},
|
||||||
ChainEvents: &contractcourt.ChainEventSubscription{},
|
ChainEvents: &contractcourt.ChainEventSubscription{},
|
||||||
SyncStates: true,
|
SyncStates: true,
|
||||||
|
BatchTicker: &mockTicker{carolTicker.C},
|
||||||
|
BatchSize: 10,
|
||||||
},
|
},
|
||||||
carolChannel,
|
carolChannel,
|
||||||
startingHeight,
|
startingHeight,
|
||||||
@ -889,7 +922,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
<-carolChannelLink.(*channelLink).htlcUpdates
|
select {
|
||||||
|
case <-carolChannelLink.(*channelLink).htlcUpdates:
|
||||||
|
case <-carolChannelLink.(*channelLink).quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -897,17 +934,21 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
|||||||
aliceServer: aliceServer,
|
aliceServer: aliceServer,
|
||||||
aliceChannelLink: aliceChannelLink.(*channelLink),
|
aliceChannelLink: aliceChannelLink.(*channelLink),
|
||||||
aliceBlockEpoch: aliceEpochChan,
|
aliceBlockEpoch: aliceEpochChan,
|
||||||
|
aliceTicker: aliceTicker,
|
||||||
|
|
||||||
firstBobChannelLink: firstBobChannelLink.(*channelLink),
|
firstBobChannelLink: firstBobChannelLink.(*channelLink),
|
||||||
bobFirstBlockEpoch: bobFirstEpochChan,
|
bobFirstBlockEpoch: bobFirstEpochChan,
|
||||||
|
firstBobTicker: firstBobTicker,
|
||||||
|
|
||||||
bobServer: bobServer,
|
bobServer: bobServer,
|
||||||
secondBobChannelLink: secondBobChannelLink.(*channelLink),
|
secondBobChannelLink: secondBobChannelLink.(*channelLink),
|
||||||
bobSecondBlockEpoch: bobSecondEpochChan,
|
bobSecondBlockEpoch: bobSecondEpochChan,
|
||||||
|
secondBobTicker: secondBobTicker,
|
||||||
|
|
||||||
carolChannelLink: carolChannelLink.(*channelLink),
|
carolChannelLink: carolChannelLink.(*channelLink),
|
||||||
carolServer: carolServer,
|
carolServer: carolServer,
|
||||||
carolBlockEpoch: carolBlockEpoch,
|
carolBlockEpoch: carolBlockEpoch,
|
||||||
|
carolTicker: carolTicker,
|
||||||
|
|
||||||
feeEstimator: feeEstimator,
|
feeEstimator: feeEstimator,
|
||||||
globalPolicy: globalPolicy,
|
globalPolicy: globalPolicy,
|
||||||
|
Loading…
Reference in New Issue
Block a user