Skip to content

Commit 6681d38

Browse files
authored
Merge pull request juju#13603 from manadart/2.9-caas-firewaller-races
juju#13603 The race test job runs quite slowly on arm64. It turns up race conditions in the CAAS firewaller worker tests. Here we do some synchronising to ensure tests pass without races. ## QA steps run the `WorkerSuite` tests in a loop with the `-race` flag. ## Documentation changes None. ## Bug reference N/A
2 parents 9fcde4e + e466a4e commit 6681d38

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

worker/caasfirewaller/worker_test.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,36 +271,38 @@ func (s *WorkerSuite) TestWatcherErrorStopsWorker(c *gc.C) {
271271
s.sendApplicationChange(c, "gitlab")
272272

273273
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)
276276
err = workertest.CheckKilled(c, w)
277277
c.Assert(err, gc.ErrorMatches, "splat")
278278
}
279279

280280
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-
285281
s.charmGetter.charmInfo.Manifest = &charm.Manifest{Bases: []charm.Base{{}}}
286282
s.charmGetter.charmInfo.Meta = &charm.Meta{}
287283

284+
w, err := caasfirewaller.NewWorker(s.config)
285+
c.Assert(err, jc.ErrorIsNil)
286+
288287
s.sendApplicationChange(c, "gitlab")
288+
s.waitCharmGetterCalls(c, "ApplicationCharmInfo")
289+
290+
workertest.CleanKill(c, w)
289291

290-
s.charmGetter.CheckCallNames(c, "ApplicationCharmInfo")
291292
s.lifeGetter.CheckNoCalls(c)
292293
}
293294

294295
func (s *WorkerSuite) TestCharmNotFound(c *gc.C) {
295296
w, err := caasfirewaller.NewWorker(s.config)
296297
c.Assert(err, jc.ErrorIsNil)
297-
defer workertest.CleanKill(c, w)
298298

299299
s.charmGetter.charmInfo = nil
300300

301301
s.sendApplicationChange(c, "gitlab")
302+
s.waitCharmGetterCalls(c, "ApplicationCharmInfo")
303+
304+
workertest.CleanKill(c, w)
302305

303-
s.charmGetter.CheckCallNames(c, "ApplicationCharmInfo")
304306
s.lifeGetter.CheckNoCalls(c)
305307
}
306308

@@ -311,7 +313,7 @@ func (s *WorkerSuite) TestCharmChangesToV2(c *gc.C) {
311313

312314
s.sendApplicationChange(c, "gitlab")
313315
s.waitCharmGetterCalls(c, "ApplicationCharmInfo")
314-
s.lifeGetter.CheckCallNames(c, "Life")
316+
s.waitLifeGetterCalls(c, "Life")
315317

316318
s.charmGetter.charmInfo.Manifest = &charm.Manifest{Bases: []charm.Base{{}}}
317319
s.charmGetter.charmInfo.Meta = &charm.Meta{}
@@ -323,11 +325,25 @@ func (s *WorkerSuite) TestCharmChangesToV2(c *gc.C) {
323325
}
324326

325327
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) {
326342
for a := coretesting.LongAttempt.Start(); a.Next(); {
327-
if len(s.charmGetter.Calls()) >= len(names) {
343+
if len(stub.Calls()) >= len(names) {
328344
break
329345
}
330346
}
331-
s.charmGetter.CheckCallNames(c, names...)
332-
s.charmGetter.ResetCalls()
347+
stub.CheckCallNames(c, names...)
348+
stub.ResetCalls()
333349
}

0 commit comments

Comments
 (0)