@@ -271,36 +271,38 @@ func (s *WorkerSuite) TestWatcherErrorStopsWorker(c *gc.C) {
271
271
s .sendApplicationChange (c , "gitlab" )
272
272
273
273
s .applicationGetter .appWatcher .KillErr (errors .New ("splat" ))
274
- workertest .CheckKilled (c , s .applicationGetter .appWatcher )
275
- workertest .CheckKilled (c , s .applicationGetter .allWatcher )
274
+ _ = workertest .CheckKilled (c , s .applicationGetter .appWatcher )
275
+ _ = workertest .CheckKilled (c , s .applicationGetter .allWatcher )
276
276
err = workertest .CheckKilled (c , w )
277
277
c .Assert (err , gc .ErrorMatches , "splat" )
278
278
}
279
279
280
280
func (s * WorkerSuite ) TestV2CharmSkipProcessing (c * gc.C ) {
281
- w , err := caasfirewaller .NewWorker (s .config )
282
- c .Assert (err , jc .ErrorIsNil )
283
- defer workertest .CleanKill (c , w )
284
-
285
281
s .charmGetter .charmInfo .Manifest = & charm.Manifest {Bases : []charm.Base {{}}}
286
282
s .charmGetter .charmInfo .Meta = & charm.Meta {}
287
283
284
+ w , err := caasfirewaller .NewWorker (s .config )
285
+ c .Assert (err , jc .ErrorIsNil )
286
+
288
287
s .sendApplicationChange (c , "gitlab" )
288
+ s .waitCharmGetterCalls (c , "ApplicationCharmInfo" )
289
+
290
+ workertest .CleanKill (c , w )
289
291
290
- s .charmGetter .CheckCallNames (c , "ApplicationCharmInfo" )
291
292
s .lifeGetter .CheckNoCalls (c )
292
293
}
293
294
294
295
func (s * WorkerSuite ) TestCharmNotFound (c * gc.C ) {
295
296
w , err := caasfirewaller .NewWorker (s .config )
296
297
c .Assert (err , jc .ErrorIsNil )
297
- defer workertest .CleanKill (c , w )
298
298
299
299
s .charmGetter .charmInfo = nil
300
300
301
301
s .sendApplicationChange (c , "gitlab" )
302
+ s .waitCharmGetterCalls (c , "ApplicationCharmInfo" )
303
+
304
+ workertest .CleanKill (c , w )
302
305
303
- s .charmGetter .CheckCallNames (c , "ApplicationCharmInfo" )
304
306
s .lifeGetter .CheckNoCalls (c )
305
307
}
306
308
@@ -311,7 +313,7 @@ func (s *WorkerSuite) TestCharmChangesToV2(c *gc.C) {
311
313
312
314
s .sendApplicationChange (c , "gitlab" )
313
315
s .waitCharmGetterCalls (c , "ApplicationCharmInfo" )
314
- s .lifeGetter . CheckCallNames (c , "Life" )
316
+ s .waitLifeGetterCalls (c , "Life" )
315
317
316
318
s .charmGetter .charmInfo .Manifest = & charm.Manifest {Bases : []charm.Base {{}}}
317
319
s .charmGetter .charmInfo .Meta = & charm.Meta {}
@@ -323,11 +325,25 @@ func (s *WorkerSuite) TestCharmChangesToV2(c *gc.C) {
323
325
}
324
326
325
327
func (s * WorkerSuite ) waitCharmGetterCalls (c * gc.C , names ... string ) {
328
+ waitStubCalls (c , & s .charmGetter , names ... )
329
+ }
330
+
331
+ func (s * WorkerSuite ) waitLifeGetterCalls (c * gc.C , names ... string ) {
332
+ waitStubCalls (c , & s .lifeGetter , names ... )
333
+ }
334
+
335
+ type waitStub interface {
336
+ Calls () []testing.StubCall
337
+ CheckCallNames (c * gc.C , expected ... string ) bool
338
+ ResetCalls ()
339
+ }
340
+
341
+ func waitStubCalls (c * gc.C , stub waitStub , names ... string ) {
326
342
for a := coretesting .LongAttempt .Start (); a .Next (); {
327
- if len (s . charmGetter .Calls ()) >= len (names ) {
343
+ if len (stub .Calls ()) >= len (names ) {
328
344
break
329
345
}
330
346
}
331
- s . charmGetter .CheckCallNames (c , names ... )
332
- s . charmGetter .ResetCalls ()
347
+ stub .CheckCallNames (c , names ... )
348
+ stub .ResetCalls ()
333
349
}
0 commit comments