diff options
| -rw-r--r-- | overlord/snapstate/autorefresh.go | 4 | ||||
| -rw-r--r-- | overlord/snapstate/autorefresh_test.go | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/overlord/snapstate/autorefresh.go b/overlord/snapstate/autorefresh.go index 36bfdbdb54..71f50cfc75 100644 --- a/overlord/snapstate/autorefresh.go +++ b/overlord/snapstate/autorefresh.go @@ -442,9 +442,7 @@ func refreshScheduleManaged(st *state.State) (managed bool, legacy bool) { } // if not set, fallback to refresh.schedule if confStr == "" { - tr := config.NewTransaction(st) - err := tr.Get("core", "refresh.schedule", &confStr) - if err != nil { + if err := tr.Get("core", "refresh.schedule", &confStr); err != nil { return false, legacy } legacy = true diff --git a/overlord/snapstate/autorefresh_test.go b/overlord/snapstate/autorefresh_test.go index 70c5a87913..d5f3a1af91 100644 --- a/overlord/snapstate/autorefresh_test.go +++ b/overlord/snapstate/autorefresh_test.go @@ -163,6 +163,35 @@ func (s *autoRefreshTestSuite) TestLastRefreshRefreshManaged(c *C) { } } +func (s *autoRefreshTestSuite) TestRefreshManagedTimerWins(c *C) { + snapstate.CanManageRefreshes = func(st *state.State) bool { + return true + } + defer func() { snapstate.CanManageRefreshes = nil }() + + s.state.Lock() + defer s.state.Unlock() + + tr := config.NewTransaction(s.state) + // the "refresh.timer" setting always takes precedence over + // refresh.schedule + tr.Set("core", "refresh.timer", "00:00-12:00") + tr.Set("core", "refresh.schedule", "managed") + tr.Commit() + + af := snapstate.NewAutoRefresh(s.state) + s.state.Unlock() + err := af.Ensure() + s.state.Lock() + c.Check(err, IsNil) + c.Check(s.store.ops, DeepEquals, []string{"list-refresh"}) + + refreshScheduleStr, legacy, err := af.RefreshSchedule() + c.Check(refreshScheduleStr, Equals, "00:00-12:00") + c.Check(legacy, Equals, false) + c.Check(err, IsNil) +} + func (s *autoRefreshTestSuite) TestLastRefreshNoRefreshNeeded(c *C) { s.state.Lock() s.state.Set("last-refresh", time.Now()) |
