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

Unified Diff: state/state_test.go

Issue 10891044: upgrader: new WatchForEnvironConfigChanges
Patch Set: upgrader: new WatchForEnvironConfigChanges Created 11 years, 9 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « state/apiserver/upgrader/upgrader_test.go ('k') | state/watcher.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/state_test.go
=== modified file 'state/state_test.go'
--- state/state_test.go 2013-07-03 15:14:20 +0000
+++ state/state_test.go 2013-07-04 14:12:18 +0000
@@ -1093,6 +1093,49 @@
assertChange(attrs{"fancy-new-key": "arbitrary-value"})
}
+// setAgentVersion sets the current agent version in the state's
+// environment configuration.
+func setAgentVersion(st *state.State, vers version.Number) error {
+ cfg, err := st.EnvironConfig()
+ if err != nil {
+ return err
+ }
+ cfg, err = cfg.Apply(map[string]interface{}{"agent-version": vers.String()})
+ if err != nil {
+ panic(fmt.Errorf("config refused agent-version: %v", err))
+ }
+ return st.SetEnvironConfig(cfg)
+}
+
+func (s *StateSuite) TestWatchForEnvironConfigChanges(c *C) {
+ cur := version.Current.Number
+ err := setAgentVersion(s.State, cur)
+ c.Assert(err, IsNil)
+ w := s.State.WatchForEnvironConfigChanges()
+ defer statetesting.AssertStop(c, w)
+
+ wc := statetesting.NewNotifyWatcherC(c, s.State, w)
+ // Initially we get one change notification
+ wc.AssertOneChange()
+
+ // Multiple changes will only result in a single change notification
+ newVersion := cur
+ newVersion.Minor += 1
+ err = setAgentVersion(s.State, newVersion)
+ c.Assert(err, IsNil)
+
+ newerVersion := newVersion
+ newerVersion.Minor += 1
+ err = setAgentVersion(s.State, newerVersion)
+ c.Assert(err, IsNil)
+ wc.AssertOneChange()
+
+ // Setting it to the same value does not trigger a change notification
+ err = setAgentVersion(s.State, newerVersion)
+ c.Assert(err, IsNil)
+ wc.AssertNoChange()
+}
+
func (s *StateSuite) TestWatchEnvironConfigCorruptConfig(c *C) {
cfg, err := s.State.EnvironConfig()
c.Assert(err, IsNil)
« no previous file with comments | « state/apiserver/upgrader/upgrader_test.go ('k') | state/watcher.go » ('j') | no next file with comments »

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