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

Unified Diff: state/cleanup_test.go

Issue 92630043: cleanup code to remove pending Actions (Closed)
Patch Set: cleanup code to remove pending Actions Created 10 years, 10 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/cleanup.go ('k') | state/service.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: state/cleanup_test.go
=== modified file 'state/cleanup_test.go'
--- state/cleanup_test.go 2014-05-20 17:57:10 +0000
+++ state/cleanup_test.go 2014-05-27 14:02:22 +0000
@@ -1,3 +1,6 @@
+// Copyright 2014 Canonical Ltd.
+// Licensed under the AGPLv3, see LICENCE file for details.
+
package state_test
import (
@@ -88,13 +91,16 @@
}
// The first cleanup Destroys the service, which
- // schedules another cleanup to destroy the units.
- s.assertNeedsCleanup(c)
- s.assertCleanupRuns(c)
+ // schedules another cleanup to destroy the units,
+ // then we need another pass for the actions cleanup
+ // which is queued on the next pass
+ s.assertCleanupCount(c, 2)
for _, unit := range units {
err = unit.Refresh()
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
+
+ // Now we should have all the cleanups done
s.assertDoesNotNeedCleanup(c)
}
@@ -299,6 +305,50 @@
s.assertCleanupCount(c, 1)
}
+func (s *CleanupSuite) TestCleanupActions(c *gc.C) {
+ s.assertDoesNotNeedCleanup(c)
+
+ // Create a service with a unit.
+ mysql := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
+ unit, err := mysql.AddUnit()
+ c.Assert(err, gc.IsNil)
+
+ // check no cleanups
+ s.assertDoesNotNeedCleanup(c)
+
+ // Add a couple actions to the unit
+ _, err = unit.AddAction("action1", nil)
+ c.Assert(err, gc.IsNil)
+ _, err = unit.AddAction("action2", nil)
+ c.Assert(err, gc.IsNil)
+
+ // make sure unit still has actions
+ actions, err := s.State.UnitActions(unit.Name())
+ c.Assert(err, gc.IsNil)
+ c.Assert(len(actions), gc.Equals, 2)
+
+ // destroy unit and run cleanups
+ err = mysql.Destroy()
+ c.Assert(err, gc.IsNil)
+ s.assertCleanupRuns(c)
+
+ // make sure unit still has actions, after first cleanup pass
+ actions, err = s.State.UnitActions(unit.Name())
+ c.Assert(err, gc.IsNil)
+ c.Assert(len(actions), gc.Equals, 2)
+
+ // second cleanup pass
+ s.assertCleanupRuns(c)
+
+ // make sure unit has no actions, after second cleanup pass
+ actions, err = s.State.UnitActions(unit.Name())
+ c.Assert(err, gc.IsNil)
+ c.Assert(len(actions), gc.Equals, 0)
+
+ // check no cleanups
+ s.assertDoesNotNeedCleanup(c)
+}
+
func (s *CleanupSuite) TestNothingToCleanup(c *gc.C) {
s.assertDoesNotNeedCleanup(c)
s.assertCleanupRuns(c)
« no previous file with comments | « state/cleanup.go ('k') | state/service.go » ('j') | no next file with comments »

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