1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
12
"github.com/juju/juju/testing"
13
"github.com/juju/juju/worker/txnpruner"
16
type TxnPrunerSuite struct {
20
var _ = gc.Suite(&TxnPrunerSuite{})
22
func (s *TxnPrunerSuite) TestPrunes(c *gc.C) {
23
fakePruner := newFakeTransactionPruner()
24
interval := 10 * time.Millisecond
25
p := txnpruner.New(fakePruner, interval)
29
for i := 0; i < 5; i++ {
31
case <-fakePruner.pruneCh:
34
// Check that pruning runs at the expected interval
35
// (but not the first time around as we don't know
36
// when the worker actually started).
38
c.Assert(td >= interval, jc.IsTrue, gc.Commentf("td=%s", td))
41
case <-time.After(testing.LongWait):
42
c.Fatal("timed out waiting for pruning to happen")
47
func (s *TxnPrunerSuite) TestStops(c *gc.C) {
48
success := make(chan bool)
50
p := txnpruner.New(newFakeTransactionPruner(), time.Minute)
52
c.Assert(p.Wait(), jc.ErrorIsNil)
59
case <-time.After(testing.LongWait):
60
c.Fatal("timed out waiting for worker to stop")
64
func newFakeTransactionPruner() *fakeTransactionPruner {
65
return &fakeTransactionPruner{
66
pruneCh: make(chan bool),
70
type fakeTransactionPruner struct {
74
// MaybePruneTransactions implements the txnpruner.TransactionPruner
76
func (p *fakeTransactionPruner) MaybePruneTransactions() error {