52
51
c.Assert(err, jc.Satisfies, errors.IsNotFound)
53
52
err = units[2].Refresh()
54
53
c.Assert(err, jc.Satisfies, errors.IsNotFound)
55
// Run a final cleanup to clear the cleanup scheduled for the unit that
57
s.assertCleanupCount(c, 1)
57
60
func (s *CleanupSuite) TestCleanupEnvironmentServices(c *gc.C) {
108
111
// Destroy the service, check the relation's still around.
109
112
err = pr.svc.Destroy()
110
113
c.Assert(err, gc.IsNil)
111
s.assertNeedsCleanup(c)
112
s.assertCleanupRuns(c)
114
s.assertCleanupCount(c, 2)
113
115
err = rel.Refresh()
114
116
c.Assert(err, gc.IsNil)
115
117
c.Assert(rel.Life(), gc.Equals, state.Dying)
116
s.assertDoesNotNeedCleanup(c)
118
119
// The unit leaves scope, triggering relation removal.
119
120
err = pr.ru0.LeaveScope()
126
127
c.Assert(settings, gc.DeepEquals, map[string]interface{}{"some": "settings"})
128
129
// ...but they are on cleanup.
129
s.assertCleanupRuns(c)
130
s.assertDoesNotNeedCleanup(c)
130
s.assertCleanupCount(c, 1)
131
131
_, err = pr.ru1.ReadSettings("riak/0")
132
132
c.Assert(err, gc.ErrorMatches, `cannot read settings for unit "riak/0" in relation "riak:ring": settings not found`)
164
164
s.assertNeedsCleanup(c)
166
166
// Clean up, and check that the unit has been removed...
167
s.assertCleanupRuns(c)
168
s.assertDoesNotNeedCleanup(c)
167
s.assertCleanupCount(c, 2)
169
168
assertRemoved(c, pr.u0)
171
170
// ...and the unit has departed relation scope...
172
assertNotInScope(c, pr.ru0)
171
assertNotJoined(c, pr.ru0)
174
173
// ...but that the machine remains, and is Dead, ready for removal by the
218
217
s.assertNeedsCleanup(c)
220
219
// Clean up, and check that the container has been removed...
221
s.assertCleanupRuns(c)
222
s.assertDoesNotNeedCleanup(c)
220
s.assertCleanupCount(c, 2)
223
221
err = container.Refresh()
224
222
c.Assert(err, jc.Satisfies, errors.IsNotFound)
240
238
assertLife(c, machine, state.Dead)
241
func (s *CleanupSuite) TestCleanupDyingUnit(c *gc.C) {
242
// Create active unit, in a relation.
243
prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeGlobal)
244
err := prr.pru0.EnterScope(nil)
245
c.Assert(err, gc.IsNil)
247
// Destroy provider unit 0; check it's Dying, and a cleanup has been scheduled.
248
err = prr.pu0.Destroy()
249
c.Assert(err, gc.IsNil)
250
err = prr.pu0.Refresh()
251
c.Assert(err, gc.IsNil)
252
assertLife(c, prr.pu0, state.Dying)
253
s.assertNeedsCleanup(c)
255
// Check it's reported in scope until cleaned up.
256
assertJoined(c, prr.pru0)
257
s.assertCleanupCount(c, 1)
258
assertInScope(c, prr.pru0)
259
assertNotJoined(c, prr.pru0)
261
// Destroy the relation, and check it sticks around...
262
err = prr.rel.Destroy()
263
c.Assert(err, gc.IsNil)
264
assertLife(c, prr.rel, state.Dying)
266
// ...until the unit is removed, and really leaves scope.
267
err = prr.pu0.EnsureDead()
268
c.Assert(err, gc.IsNil)
269
err = prr.pu0.Remove()
270
c.Assert(err, gc.IsNil)
271
assertNotInScope(c, prr.pru0)
272
assertRemoved(c, prr.rel)
275
func (s *CleanupSuite) TestCleanupDyingUnitAlreadyRemoved(c *gc.C) {
276
// Create active unit, in a relation.
277
prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeGlobal)
278
err := prr.pru0.EnterScope(nil)
279
c.Assert(err, gc.IsNil)
281
// Destroy provider unit 0; check it's Dying, and a cleanup has been scheduled.
282
err = prr.pu0.Destroy()
283
c.Assert(err, gc.IsNil)
284
err = prr.pu0.Refresh()
285
c.Assert(err, gc.IsNil)
286
assertLife(c, prr.pu0, state.Dying)
287
s.assertNeedsCleanup(c)
289
// Remove the unit, and the relation.
290
err = prr.pu0.EnsureDead()
291
c.Assert(err, gc.IsNil)
292
err = prr.pu0.Remove()
293
c.Assert(err, gc.IsNil)
294
err = prr.rel.Destroy()
295
c.Assert(err, gc.IsNil)
296
assertRemoved(c, prr.rel)
298
// Check the cleanup still runs happily.
299
s.assertCleanupCount(c, 1)
243
302
func (s *CleanupSuite) TestNothingToCleanup(c *gc.C) {
244
303
s.assertDoesNotNeedCleanup(c)
245
304
s.assertCleanupRuns(c)
262
321
c.Assert(err, gc.IsNil)
263
322
c.Assert(actual, jc.IsFalse)
325
// assertCleanupCount is useful because certain cleanups cause other cleanups
326
// to be queued; it makes more sense to just run cleanup again than to unpick
327
// object destruction so that we run the cleanups inline while running cleanups.
328
func (s *CleanupSuite) assertCleanupCount(c *gc.C, count int) {
329
for i := 0; i < count; i++ {
330
c.Logf("checking cleanups %d", i)
331
s.assertNeedsCleanup(c)
332
s.assertCleanupRuns(c)
334
s.assertDoesNotNeedCleanup(c)