Skip to content

Commit

Permalink
o/snapstate: test refresh policies for classic are not run at preseed…
Browse files Browse the repository at this point in the history
… time
  • Loading branch information
pedronis authored and Meulengracht committed Jan 5, 2024
1 parent e511d8a commit 3017c60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions overlord/snapstate/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,7 @@ func MockCgroupMonitorSnapEnded(f func(string, chan<- string) error) func() {
func SetRestoredMonitoring(snapmgr *SnapManager, value bool) {
snapmgr.autoRefresh.restoredMonitoring = value
}

func SetPreseed(snapmgr *SnapManager, value bool) {
snapmgr.preseed = value
}
26 changes: 26 additions & 0 deletions overlord/snapstate/snapstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3723,6 +3723,32 @@ func (s *snapmgrTestSuite) TestEnsureRefreshesAtSeedPolicy(c *C) {
c.Check(err, IsNil)
}

func (s *snapmgrTestSuite) TestEnsureRefreshesAtSeedPolicyNopAtPreesed(c *C) {
// special policy only on classic
r := release.MockOnClassic(true)
defer r()
// set at not seeded yet
st := s.state
st.Lock()
st.Set("seeded", nil)
st.Unlock()
// preseed time
snapstate.SetPreseed(s.snapmgr, true)

s.snapmgr.Ensure()

st.Lock()
defer st.Unlock()

// check that refresh policies have *NOT* run in this case
var t1 time.Time
err := st.Get("last-refresh-hints", &t1)
c.Check(err, testutil.ErrorIs, state.ErrNoState)
tr := config.NewTransaction(st)
err = tr.Get("core", "refresh.hold", &t1)
c.Check(config.IsNoOption(err), Equals, true)
}

func (s *snapmgrTestSuite) TestEsnureCleansOldSideloads(c *C) {
filenames := func() []string {
filenames, _ := filepath.Glob(filepath.Join(dirs.SnapBlobDir, "*"))
Expand Down

0 comments on commit 3017c60

Please sign in to comment.