Browse Source

ticker+htlcswitch: rename Mock -> Force

master
Wilmer Paulino 5 years ago
parent
commit
abdd01ed9a
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
  1. 10
      htlcswitch/link_test.go
  2. 4
      htlcswitch/mock.go
  3. 2
      htlcswitch/switch_test.go
  4. 4
      htlcswitch/test_utils.go
  5. 23
      ticker/mock.go
  6. 2
      ticker/ticker.go
  7. 2
      ticker/ticker_test.go

10
htlcswitch/link_test.go

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

4
htlcswitch/mock.go

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

2
htlcswitch/switch_test.go

@ -1924,7 +1924,7 @@ func TestMultiHopPaymentForwardingEvents(t *testing.T) {
// After sending 5 of the payments, trigger the forwarding ticker, to
// 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 {
t.Fatalf("mockTicker assertion failed")
}

4
htlcswitch/test_utils.go

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

23
ticker/mock.go

@ -6,9 +6,9 @@ import (
"time"
)
// Mock implements the Ticker interface, and provides a method of
// force-feeding ticks, even while paused.
type Mock struct {
// Force implements the Ticker interface, and provides a method of force-feeding
// ticks, even while paused.
type Force struct {
isActive uint32 // used atomically
// Force is used to force-feed a ticks into the ticker. Useful for
@ -22,10 +22,13 @@ type Mock 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
func MockNew(interval time.Duration) *Mock {
m := &Mock{
func NewForce(interval time.Duration) *Force {
m := &Force{
ticker: time.NewTicker(interval).C,
Force: make(chan time.Time),
skip: make(chan struct{}),
@ -64,7 +67,7 @@ func MockNew(interval time.Duration) *Mock {
// time.
//
// NOTE: Part of the Ticker interface.
func (m *Mock) Ticks() <-chan time.Time {
func (m *Force) Ticks() <-chan time.Time {
return m.Force
}
@ -72,7 +75,7 @@ func (m *Mock) Ticks() <-chan time.Time {
// delivering scheduled events.
//
// NOTE: Part of the Ticker interface.
func (m *Mock) Resume() {
func (m *Force) Resume() {
atomic.StoreUint32(&m.isActive, 1)
}
@ -80,7 +83,7 @@ func (m *Mock) Resume() {
// regular intervals.
//
// NOTE: Part of the Ticker interface.
func (m *Mock) Pause() {
func (m *Force) Pause() {
atomic.StoreUint32(&m.isActive, 0)
// 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.
//
// NOTE: Part of the Ticker interface.
func (m *Mock) Stop() {
func (m *Force) Stop() {
m.Pause()
close(m.quit)
m.wg.Wait()

2
ticker/ticker.go

@ -46,7 +46,7 @@ type Ticker interface {
// Pause suspends the underlying ticker, such that Ticks() stops
// signaling at regular intervals. After calling Pause, the ticker
// 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
// successively.

2
ticker/ticker_test.go

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

Loading…
Cancel
Save