ticker+htlcswitch: rename Mock -> Force

This commit is contained in:
Wilmer Paulino 2019-02-06 16:48:54 -08:00
parent faccccf93f
commit abdd01ed9a
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
7 changed files with 25 additions and 22 deletions

View File

@ -1545,7 +1545,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
// Instantiate with a long interval, so that we can precisely control // Instantiate with a long interval, so that we can precisely control
// the firing via force feeding. // the firing via force feeding.
bticker := ticker.MockNew(time.Hour) bticker := ticker.NewForce(time.Hour)
aliceCfg := ChannelLinkConfig{ aliceCfg := ChannelLinkConfig{
FwrdingPolicy: globalPolicy, FwrdingPolicy: globalPolicy,
Peer: alicePeer, Peer: alicePeer,
@ -1568,7 +1568,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
Registry: invoiceRegistry, Registry: invoiceRegistry,
ChainEvents: &contractcourt.ChainEventSubscription{}, ChainEvents: &contractcourt.ChainEventSubscription{},
BatchTicker: bticker, BatchTicker: bticker,
FwdPkgGCTicker: ticker.MockNew(15 * time.Second), FwdPkgGCTicker: ticker.NewForce(15 * time.Second),
// Make the BatchSize and Min/MaxFeeUpdateTimeout large enough // Make the BatchSize and Min/MaxFeeUpdateTimeout large enough
// to not trigger commit updates automatically during tests. // to not trigger commit updates automatically during tests.
BatchSize: 10000, BatchSize: 10000,
@ -3506,7 +3506,7 @@ func TestChannelLinkShutdownDuringForward(t *testing.T) {
// unblocks after nothing has been pulled for two seconds. // unblocks after nothing has been pulled for two seconds.
waitForBobsSwitchToBlock := func() { waitForBobsSwitchToBlock := func() {
bobSwitch := n.firstBobChannelLink.cfg.Switch bobSwitch := n.firstBobChannelLink.cfg.Switch
ticker := bobSwitch.cfg.LogEventTicker.(*ticker.Mock) ticker := bobSwitch.cfg.LogEventTicker.(*ticker.Force)
timeout := time.After(15 * time.Second) timeout := time.After(15 * time.Second)
for { for {
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -3525,7 +3525,7 @@ func TestChannelLinkShutdownDuringForward(t *testing.T) {
// Define a helper method that strobes the link's batch ticker, and // Define a helper method that strobes the link's batch ticker, and
// unblocks after nothing has been pulled for two seconds. // unblocks after nothing has been pulled for two seconds.
waitForBobsIncomingLinkToBlock := func() { waitForBobsIncomingLinkToBlock := func() {
ticker := n.firstBobChannelLink.cfg.BatchTicker.(*ticker.Mock) ticker := n.firstBobChannelLink.cfg.BatchTicker.(*ticker.Force)
timeout := time.After(15 * time.Second) timeout := time.After(15 * time.Second)
for { for {
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
@ -4060,7 +4060,7 @@ func restartLink(aliceChannel *lnwallet.LightningChannel, aliceSwitch *Switch,
// Instantiate with a long interval, so that we can precisely control // Instantiate with a long interval, so that we can precisely control
// the firing via force feeding. // the firing via force feeding.
bticker := ticker.MockNew(time.Hour) bticker := ticker.NewForce(time.Hour)
aliceCfg := ChannelLinkConfig{ aliceCfg := ChannelLinkConfig{
FwrdingPolicy: globalPolicy, FwrdingPolicy: globalPolicy,
Peer: alicePeer, Peer: alicePeer,

View File

@ -163,8 +163,8 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
return nil, nil return nil, nil
}, },
Notifier: &mockNotifier{}, Notifier: &mockNotifier{},
FwdEventTicker: ticker.MockNew(DefaultFwdEventInterval), FwdEventTicker: ticker.NewForce(DefaultFwdEventInterval),
LogEventTicker: ticker.MockNew(DefaultLogInterval), LogEventTicker: ticker.NewForce(DefaultLogInterval),
NotifyActiveChannel: func(wire.OutPoint) {}, NotifyActiveChannel: func(wire.OutPoint) {},
NotifyInactiveChannel: func(wire.OutPoint) {}, NotifyInactiveChannel: func(wire.OutPoint) {},
} }

View File

@ -1924,7 +1924,7 @@ func TestMultiHopPaymentForwardingEvents(t *testing.T) {
// After sending 5 of the payments, trigger the forwarding ticker, to // After sending 5 of the payments, trigger the forwarding ticker, to
// make sure the events are properly flushed. // make sure the events are properly flushed.
bobTicker, ok := n.bobServer.htlcSwitch.cfg.FwdEventTicker.(*ticker.Mock) bobTicker, ok := n.bobServer.htlcSwitch.cfg.FwdEventTicker.(*ticker.Force)
if !ok { if !ok {
t.Fatalf("mockTicker assertion failed") t.Fatalf("mockTicker assertion failed")
} }

View File

@ -1041,8 +1041,8 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer,
ChainEvents: &contractcourt.ChainEventSubscription{}, ChainEvents: &contractcourt.ChainEventSubscription{},
SyncStates: true, SyncStates: true,
BatchSize: 10, BatchSize: 10,
BatchTicker: ticker.MockNew(batchTimeout), BatchTicker: ticker.NewForce(batchTimeout),
FwdPkgGCTicker: ticker.MockNew(fwdPkgTimeout), FwdPkgGCTicker: ticker.NewForce(fwdPkgTimeout),
MinFeeUpdateTimeout: minFeeUpdateTimeout, MinFeeUpdateTimeout: minFeeUpdateTimeout,
MaxFeeUpdateTimeout: maxFeeUpdateTimeout, MaxFeeUpdateTimeout: maxFeeUpdateTimeout,
OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {}, OnChannelFailure: func(lnwire.ChannelID, lnwire.ShortChannelID, LinkFailureError) {},

View File

@ -6,9 +6,9 @@ import (
"time" "time"
) )
// Mock implements the Ticker interface, and provides a method of // Force implements the Ticker interface, and provides a method of force-feeding
// force-feeding ticks, even while paused. // ticks, even while paused.
type Mock struct { type Force struct {
isActive uint32 // used atomically isActive uint32 // used atomically
// Force is used to force-feed a ticks into the ticker. Useful for // Force is used to force-feed a ticks into the ticker. Useful for
@ -22,10 +22,13 @@ type Mock struct {
quit chan struct{} quit chan struct{}
} }
// MockNew returns a Mock Ticker, used for testing and debugging. It supports // A compile-time constraint to ensure Force satisfies the Ticker interface.
var _ Ticker = (*Force)(nil)
// NewForce returns a Force ticker, used for testing and debugging. It supports
// the ability to force-feed events that get output by the // the ability to force-feed events that get output by the
func MockNew(interval time.Duration) *Mock { func NewForce(interval time.Duration) *Force {
m := &Mock{ m := &Force{
ticker: time.NewTicker(interval).C, ticker: time.NewTicker(interval).C,
Force: make(chan time.Time), Force: make(chan time.Time),
skip: make(chan struct{}), skip: make(chan struct{}),
@ -64,7 +67,7 @@ func MockNew(interval time.Duration) *Mock {
// time. // time.
// //
// NOTE: Part of the Ticker interface. // NOTE: Part of the Ticker interface.
func (m *Mock) Ticks() <-chan time.Time { func (m *Force) Ticks() <-chan time.Time {
return m.Force return m.Force
} }
@ -72,7 +75,7 @@ func (m *Mock) Ticks() <-chan time.Time {
// delivering scheduled events. // delivering scheduled events.
// //
// NOTE: Part of the Ticker interface. // NOTE: Part of the Ticker interface.
func (m *Mock) Resume() { func (m *Force) Resume() {
atomic.StoreUint32(&m.isActive, 1) atomic.StoreUint32(&m.isActive, 1)
} }
@ -80,7 +83,7 @@ func (m *Mock) Resume() {
// regular intervals. // regular intervals.
// //
// NOTE: Part of the Ticker interface. // NOTE: Part of the Ticker interface.
func (m *Mock) Pause() { func (m *Force) Pause() {
atomic.StoreUint32(&m.isActive, 0) atomic.StoreUint32(&m.isActive, 0)
// If the ticker fired and read isActive as true, it may still send the // If the ticker fired and read isActive as true, it may still send the
@ -95,7 +98,7 @@ func (m *Mock) Pause() {
// regular intervals, and permanently frees up any resources. // regular intervals, and permanently frees up any resources.
// //
// NOTE: Part of the Ticker interface. // NOTE: Part of the Ticker interface.
func (m *Mock) Stop() { func (m *Force) Stop() {
m.Pause() m.Pause()
close(m.quit) close(m.quit)
m.wg.Wait() m.wg.Wait()

View File

@ -46,7 +46,7 @@ type Ticker interface {
// Pause suspends the underlying ticker, such that Ticks() stops // Pause suspends the underlying ticker, such that Ticks() stops
// signaling at regular intervals. After calling Pause, the ticker // signaling at regular intervals. After calling Pause, the ticker
// should not send any ticks scheduled with the chosen interval. Forced // should not send any ticks scheduled with the chosen interval. Forced
// ticks are still permissible, as in the case of the Mock Ticker. // ticks are still permissible, as in the case of the Force Ticker.
// //
// NOTE: It MUST be safe to call Pause at any time, and more than once // NOTE: It MUST be safe to call Pause at any time, and more than once
// successively. // successively.

View File

@ -20,7 +20,7 @@ var tickers = []struct {
}, },
{ {
"mock ticker", "mock ticker",
ticker.MockNew(interval), ticker.NewForce(interval),
}, },
} }