Skip to content

Commit

Permalink
Use the mock clock in TestMeterStatusSuccesfulSend.
Browse files Browse the repository at this point in the history
This fixes an "intermittent" test failure which could have been caused
by the real-world clock time from setup to the affected test being > 1s.
  • Loading branch information
Casey Marshall committed Oct 13, 2016
1 parent 6cf1bc9 commit 9291126
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apiserver/metricsmanager/metricsmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
type metricsManagerSuite struct {
jujujutesting.JujuConnSuite

clock *jujutesting.Clock
metricsmanager *metricsmanager.MetricsManagerAPI
authorizer apiservertesting.FakeAuthorizer
unit *state.Unit
Expand All @@ -39,7 +40,8 @@ func (s *metricsManagerSuite) SetUpTest(c *gc.C) {
Tag: names.NewMachineTag("0"),
EnvironManager: true,
}
manager, err := metricsmanager.NewMetricsManagerAPI(s.State, nil, s.authorizer, jujutesting.NewClock(time.Now()))
s.clock = jujutesting.NewClock(time.Now())
manager, err := metricsmanager.NewMetricsManagerAPI(s.State, nil, s.authorizer, s.clock)
c.Assert(err, jc.ErrorIsNil)
s.metricsmanager = manager
meteredCharm := s.Factory.MakeCharm(c, &factory.CharmParams{Name: "metered", URL: "cs:quantal/metered"})
Expand Down Expand Up @@ -185,7 +187,7 @@ func (s *metricsManagerSuite) TestMeterStatusOnConsecutiveErrors(c *gc.C) {

func (s *metricsManagerSuite) TestMeterStatusSuccessfulSend(c *gc.C) {
var sender testing.MockSender
pastTime := time.Now().Add(-time.Second)
pastTime := s.clock.Now().Add(-time.Second)
metric := state.Metric{"pings", "5", pastTime}
s.Factory.MakeMetric(c, &factory.MetricParams{Unit: s.unit, Sent: false, Time: &pastTime, Metrics: []state.Metric{metric}})
metricsmanager.PatchSender(&sender)
Expand Down

0 comments on commit 9291126

Please sign in to comment.