Skip to content

Commit

Permalink
overlord: fix race in refresh monitoring tests
Browse files Browse the repository at this point in the history
Fix a race in refresh monitoring tests, where the snap-app-presence monitoring
code could call EnsureBefore(0) before the overlord Loop() was fully running.

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo authored and miguelpires committed Feb 22, 2024
1 parent 01dcdd0 commit dc3fb24
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions overlord/managers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13803,14 +13803,15 @@ func (s *mgrsSuite) TestAutoRefreshOneWithMonitoring(c *C) {
// refresh-candidate should not be empty
c.Assert(candidates, HasLen, 1)

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

// what's supposed to happen now is the file removal will be noticed, a
// change will be kicked off and the snap will get a refresh
st.Unlock()
s.o.Loop()

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

chg = waitForReadyChangeKind(c, st, "auto-refresh")
err = s.o.Stop()
c.Assert(err, IsNil)
Expand Down Expand Up @@ -13904,15 +13905,15 @@ func (s *mgrsSuite) TestAutoRefreshWithMonitoring(c *C) {
// refresh-candidate should not be empty
c.Check(candidates, HasLen, 1)

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

// what's supposed to happen now is the file removal will be noticed, a
// change will be kicked off and the snap will get a refresh
st.Unlock()
s.o.Loop()

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

chg = waitForReadyChangeKind(c, st, "auto-refresh")
err = s.o.Stop()
c.Assert(err, IsNil)
Expand Down Expand Up @@ -14037,15 +14038,16 @@ func (s *mgrsSuite) TestAutoRefreshStoreUpdateWhileWaitingWithMonitoring(c *C) {
dumpTasks(c, "after settle", chg.Tasks())
c.Assert(chg.Err(), ErrorMatches, `(?s).*snap "held-with-app-running" has running apps.*`)

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

// what's supposed to happen now is the file removal will be noticed, a
// change will be kicked off and the snap will get a refresh
st.Unlock()
s.o.Loop()

// remove the entry as if the app has closed, this can be done only
// after calling Loop()
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

chg = waitForReadyChangeKind(c, st, "auto-refresh")
err = s.o.Stop()
c.Assert(err, IsNil)
Expand Down Expand Up @@ -14152,15 +14154,16 @@ func (s *mgrsSuite) TestAutoRefreshStorePreDownloadWhileWaitingWithMonitoring(c
c.Check(candidates, HasLen, 1)
c.Assert(candidates["held-with-app-running"], NotNil)

// remove the entry as if the app has closed
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

// what's supposed to happen now is the file removal will be noticed, a
// change will be kicked off and the snap will get a refresh
st.Unlock()
s.o.Loop()

// remove the entry as if the app has closed, this can be done only
// after calling Loop()
err = os.RemoveAll(filepath.Join(dirs.GlobalRootDir, "/sys/fs/cgroup/snap.held-with-app-running.app.scope"))
c.Assert(err, IsNil)

chgAuto := waitForReadyChangeKind(c, st, "auto-refresh")
err = s.o.Stop()
c.Assert(err, IsNil)
Expand Down

0 comments on commit dc3fb24

Please sign in to comment.