Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1586)

Side by Side Diff: worker/charmrevisionworker/revisionupdater_test.go

Issue 49500043: New worker to run the charm version updater (Closed)
Patch Set: New worker to run the charm version updater Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package charmrevisionworker_test
5
6 import (
7 stdtesting "testing"
8 "time"
9
10 gc "launchpad.net/gocheck"
11
12 "launchpad.net/juju-core/charm"
13 "launchpad.net/juju-core/state"
14 "launchpad.net/juju-core/state/api"
15 "launchpad.net/juju-core/state/apiserver/charmrevisionupdater/testing"
16 coretesting "launchpad.net/juju-core/testing"
17 jc "launchpad.net/juju-core/testing/checkers"
18 "launchpad.net/juju-core/utils"
19 "launchpad.net/juju-core/worker/charmrevisionworker"
20 )
21
22 func TestPackage(t *stdtesting.T) {
23 coretesting.MgoTestPackage(t)
24 }
25
26 type RevisionUpdateSuite struct {
27 testing.CharmSuite
28
29 st *api.State
30 versionUpdater *charmrevisionworker.RevisionUpdateWorker
31 }
32
33 var _ = gc.Suite(&RevisionUpdateSuite{})
34
35 func (s *RevisionUpdateSuite) SetUpSuite(c *gc.C) {
36 c.Assert(*charmrevisionworker.Interval, gc.Equals, 6*time.Hour)
thumper 2014/01/17 02:21:07 Really? Why?
wallyworld 2014/01/17 13:26:07 Cause I thought 24 hours was too long to wait if a
37 s.CharmSuite.SetUpSuite(c)
38 }
39
40 func (s *RevisionUpdateSuite) SetUpTest(c *gc.C) {
41 s.CharmSuite.SetUpTest(c)
42
43 machine, err := s.State.AddMachine("quantal", state.JobManageState)
44 c.Assert(err, gc.IsNil)
45 password, err := utils.RandomPassword()
46 c.Assert(err, gc.IsNil)
47 err = machine.SetPassword(password)
48 c.Assert(err, gc.IsNil)
49 err = machine.SetProvisioned("i-manager", "fake_nonce", nil)
50 c.Assert(err, gc.IsNil)
51 s.st = s.OpenAPIAsMachine(c, machine.Tag(), password, "fake_nonce")
52 c.Assert(s.st, gc.NotNil)
53 }
54
55 func (s *RevisionUpdateSuite) TearDownTest(c *gc.C) {
56 c.Assert(s.versionUpdater.Stop(), gc.IsNil)
thumper 2014/01/17 02:21:07 Why not do this with addCleanup?
wallyworld 2014/01/17 13:26:07 Can do
57 s.CharmSuite.TearDownTest(c)
58 }
59
60 func (s *RevisionUpdateSuite) runUpdater(c *gc.C, updateInterval time.Duration) {
61 s.PatchValue(charmrevisionworker.Interval, updateInterval)
62 revisionUpdaterState := s.st.CharmRevisionUpdater()
63 c.Assert(revisionUpdaterState, gc.NotNil)
64
65 s.versionUpdater = charmrevisionworker.NewRevisionUpdateWorker(revisionU pdaterState)
66 }
67
68 func (s *RevisionUpdateSuite) checkCharmRevision(c *gc.C, expectedRev int) bool {
69 checkRevision := func() bool {
70 curl := charm.MustParseURL("cs:quantal/mysql")
71 placeholder, err := s.State.LatestPlaceholderCharm(curl)
72 return err == nil && placeholder.String() == curl.WithRevision(e xpectedRev).String()
73 }
74
75 success := false
76 for attempt := coretesting.LongAttempt.Start(); attempt.Next(); {
77 if success = checkRevision(); success {
78 break
79 }
80 }
81 return success
82 }
83
84 func (s *RevisionUpdateSuite) TestVersionUpdateRunsInitially(c *gc.C) {
85 s.SetupScenario(c)
86
87 // Run the updater with a long update interval to ensure only the initia l
88 // update on startup is run.
89 s.runUpdater(c, time.Hour)
90 c.Assert(s.checkCharmRevision(c, 23), jc.IsTrue)
91 }
92
93 func (s *RevisionUpdateSuite) TestVersionUpdateRunsPeriodically(c *gc.C) {
94 s.SetupScenario(c)
95
96 // Start the updater and check the initial status.
97 s.runUpdater(c, 5*time.Millisecond)
98 c.Assert(s.checkCharmRevision(c, 23), jc.IsTrue)
99
100 // Make some changes
101 s.UpdateStoreRevision("cs:quantal/mysql", 24)
102 // Check the results of the latest changes.
103 c.Assert(s.checkCharmRevision(c, 24), jc.IsTrue)
104 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b