github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/worker/uniter/export_test.go (about)

     1  // Copyright 2013, 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  )
    10  
    11  func SetUniterObserver(u *Uniter, observer UniterExecutionObserver) {
    12  	u.observer = observer
    13  }
    14  
    15  var (
    16  	IdleWaitTime        = &idleWaitTime
    17  	LeadershipGuarantee = &leadershipGuarantee
    18  )
    19  
    20  // manualTicker will be used to generate collect-metrics events
    21  // in a time-independent manner for testing.
    22  type ManualTicker struct {
    23  	c chan time.Time
    24  }
    25  
    26  // Tick sends a signal on the ticker channel.
    27  func (t *ManualTicker) Tick() error {
    28  	select {
    29  	case t.c <- time.Now():
    30  	default:
    31  		return fmt.Errorf("ticker channel blocked")
    32  	}
    33  	return nil
    34  }
    35  
    36  // ReturnTimer can be used to replace the metrics signal generator.
    37  func (t *ManualTicker) ReturnTimer(now, lastRun time.Time, interval time.Duration) <-chan time.Time {
    38  	return t.c
    39  }
    40  
    41  func NewManualTicker() *ManualTicker {
    42  	return &ManualTicker{
    43  		c: make(chan time.Time, 1),
    44  	}
    45  }
    46  
    47  func NewTestingMetricsTimerChooser(active TimedSignal) *timerChooser {
    48  	return &timerChooser{
    49  		active:   active,
    50  		inactive: inactiveMetricsTimer,
    51  	}
    52  }
    53  
    54  func UpdateStatusSignal(now, lastSignal time.Time, interval time.Duration) <-chan time.Time {
    55  	return updateStatusSignal(now, lastSignal, interval)
    56  }
    57  
    58  func ActiveMetricsSignal(now, lastSignal time.Time, interval time.Duration) <-chan time.Time {
    59  	return activeMetricsTimer(now, lastSignal, interval)
    60  }