~ubuntu-branches/ubuntu/vivid/juju-core/vivid-updates

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/status_history_test.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package state_test
 
5
 
 
6
import (
 
7
        jc "github.com/juju/testing/checkers"
 
8
        gc "gopkg.in/check.v1"
 
9
 
 
10
        "github.com/juju/juju/state"
 
11
        statetesting "github.com/juju/juju/state/testing"
 
12
        "github.com/juju/juju/testing/factory"
 
13
)
 
14
 
 
15
type StatusHistorySuite struct {
 
16
        statetesting.StateSuite
 
17
}
 
18
 
 
19
var _ = gc.Suite(&StatusHistorySuite{})
 
20
 
 
21
func (s *StatusHistorySuite) TestPruneStatusHistory(c *gc.C) {
 
22
 
 
23
        // NOTE: the behaviour is bad, and the test is ugly. I'm just verifying
 
24
        // the existing logic here.
 
25
        //
 
26
        // If you get the opportunity to fix this, you'll want a better shape of
 
27
        // test (that injects a usable clock dependency, apart from anything else,
 
28
        // and checks that we do our best to maintain a usable span of history
 
29
        // rather than an arbitrary limit per entity. And isn't O(N) on status
 
30
        // count in the environment).
 
31
 
 
32
        const count = 3
 
33
        units := make([]*state.Unit, count)
 
34
        agents := make([]*state.UnitAgent, count)
 
35
        service := s.Factory.MakeService(c, nil)
 
36
        for i := 0; i < count; i++ {
 
37
                units[i] = s.Factory.MakeUnit(c, &factory.UnitParams{Service: service})
 
38
                agents[i] = units[i].Agent()
 
39
        }
 
40
 
 
41
        primeUnitStatusHistory(c, units[0], 10)
 
42
        primeUnitStatusHistory(c, units[1], 50)
 
43
        primeUnitStatusHistory(c, units[2], 100)
 
44
        primeUnitAgentStatusHistory(c, agents[0], 100)
 
45
        primeUnitAgentStatusHistory(c, agents[1], 50)
 
46
        primeUnitAgentStatusHistory(c, agents[2], 10)
 
47
 
 
48
        err := state.PruneStatusHistory(s.State, 30)
 
49
        c.Assert(err, jc.ErrorIsNil)
 
50
 
 
51
        history, err := units[0].StatusHistory(50)
 
52
        c.Assert(err, jc.ErrorIsNil)
 
53
        c.Assert(history, gc.HasLen, 11)
 
54
        checkInitialWorkloadStatus(c, history[10])
 
55
        for i, statusInfo := range history[:10] {
 
56
                checkPrimedUnitStatus(c, statusInfo, 9-i)
 
57
        }
 
58
 
 
59
        history, err = units[1].StatusHistory(50)
 
60
        c.Assert(err, jc.ErrorIsNil)
 
61
        c.Assert(history, gc.HasLen, 30)
 
62
        for i, statusInfo := range history {
 
63
                checkPrimedUnitStatus(c, statusInfo, 49-i)
 
64
        }
 
65
 
 
66
        history, err = units[2].StatusHistory(50)
 
67
        c.Assert(err, jc.ErrorIsNil)
 
68
        c.Assert(history, gc.HasLen, 30)
 
69
        for i, statusInfo := range history {
 
70
                checkPrimedUnitStatus(c, statusInfo, 99-i)
 
71
        }
 
72
 
 
73
        history, err = agents[0].StatusHistory(50)
 
74
        c.Assert(err, jc.ErrorIsNil)
 
75
        c.Assert(history, gc.HasLen, 30)
 
76
        for i, statusInfo := range history {
 
77
                checkPrimedUnitAgentStatus(c, statusInfo, 99-i)
 
78
        }
 
79
 
 
80
        history, err = agents[1].StatusHistory(50)
 
81
        c.Assert(err, jc.ErrorIsNil)
 
82
        c.Assert(history, gc.HasLen, 30)
 
83
        for i, statusInfo := range history {
 
84
                checkPrimedUnitAgentStatus(c, statusInfo, 49-i)
 
85
        }
 
86
 
 
87
        history, err = agents[2].StatusHistory(50)
 
88
        c.Assert(err, jc.ErrorIsNil)
 
89
        c.Assert(history, gc.HasLen, 11)
 
90
        checkInitialUnitAgentStatus(c, history[10])
 
91
        for i, statusInfo := range history[:10] {
 
92
                checkPrimedUnitAgentStatus(c, statusInfo, 9-i)
 
93
        }
 
94
}