Skip to content

Commit

Permalink
Merge pull request juju#16115 from manadart/3.1-action-pruner-test-fix
Browse files Browse the repository at this point in the history
juju#16115

JUJU-4435

`TestRunStop` from the action-pruner worker suite starts a watcher at the top of its event loop. The test kills the worker immediately, but the first selected case will sometimes be the initial event for the watcher instead of the killed catacomb.

Here we accommodate this possibility and mock the `ModelConfig` method.

## QA steps

Worker tests for `actionpruner` pass consistently.
  • Loading branch information
jujubot authored Aug 17, 2023
2 parents 87b82f7 + 2314cb4 commit c72e543
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion worker/actionpruner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
gc "gopkg.in/check.v1"

"github.com/juju/juju/core/watcher/watchertest"
"github.com/juju/juju/environs/config"
coretesting "github.com/juju/juju/testing"
"github.com/juju/juju/worker/actionpruner"
"github.com/juju/juju/worker/pruner"
"github.com/juju/juju/worker/pruner/mocks"
Expand All @@ -27,18 +29,33 @@ func (s *PrunerSuite) TestRunStop(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()

cfg, err := config.New(false, map[string]interface{}{
"name": "test",
"type": "manual",
"uuid": coretesting.ModelTag.Id(),
"max-action-results-age": "2h",
"max-action-results-size": "2GiB",
})
c.Assert(err, jc.ErrorIsNil)

ch := make(chan struct{}, 1)
ch <- struct{}{}
w := watchertest.NewMockNotifyWatcher(ch)

facade := mocks.NewMockFacade(ctrl)
facade.EXPECT().WatchForModelConfigChanges().Return(w, nil)

// Depending on the host compute speed, the loop may select either
// the watcher change event, or the catacomb's dying event first.
facade.EXPECT().ModelConfig().Return(cfg, nil).AnyTimes()

updater, err := actionpruner.New(pruner.Config{
Facade: facade,
PruneInterval: 0,
PruneInterval: time.Minute,
Clock: testclock.NewClock(time.Now()),
Logger: loggo.GetLogger("test"),
})

c.Assert(err, jc.ErrorIsNil)
workertest.CleanKill(c, updater)
}

0 comments on commit c72e543

Please sign in to comment.