コード例 #1
0
ファイル: worker_test.go プロジェクト: bac/juju
func (s *statusHistoryPrunerSuite) TestWorkerWontCallPruneBeforeFiringTimer(c *gc.C) {
	fakeTimer := newMockTimer(coretesting.LongWait)

	fakeTimerFunc := func(d time.Duration) worker.PeriodicTimer {
		// construction of timer should be with 0 because we intend it to
		// run once before waiting.
		c.Assert(d, gc.Equals, 0*time.Nanosecond)
		return fakeTimer
	}
	facade := newFakeFacade()
	conf := statushistorypruner.Config{
		Facade:         facade,
		MaxHistoryTime: 1 * time.Second,
		MaxHistoryMB:   3,
		PruneInterval:  coretesting.ShortWait,
		NewTimer:       fakeTimerFunc,
	}

	pruner, err := statushistorypruner.New(conf)
	c.Check(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) {
		c.Assert(worker.Stop(pruner), jc.ErrorIsNil)
	})

	select {
	case <-facade.passedMaxHistoryMB:
		c.Fatal("called before firing timer.")
	case <-time.After(coretesting.LongWait):
	}
}
コード例 #2
0
ファイル: worker_test.go プロジェクト: bac/juju
func (s *statusHistoryPrunerSuite) TestWorkerCallsPrune(c *gc.C) {
	fakeTimer := newMockTimer(coretesting.LongWait)

	fakeTimerFunc := func(d time.Duration) worker.PeriodicTimer {
		// construction of timer should be with 0 because we intend it to
		// run once before waiting.
		c.Assert(d, gc.Equals, 0*time.Nanosecond)
		return fakeTimer
	}
	facade := newFakeFacade()
	conf := statushistorypruner.Config{
		Facade:         facade,
		MaxHistoryTime: 1 * time.Second,
		MaxHistoryMB:   3,
		PruneInterval:  coretesting.ShortWait,
		NewTimer:       fakeTimerFunc,
	}

	pruner, err := statushistorypruner.New(conf)
	c.Check(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) {
		c.Assert(worker.Stop(pruner), jc.ErrorIsNil)
	})

	err = fakeTimer.fire()
	c.Check(err, jc.ErrorIsNil)

	var passedMB int
	select {
	case passedMB = <-facade.passedMaxHistoryMB:
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for passed logs to pruner")
	}
	c.Assert(passedMB, gc.Equals, 3)

	// Reset will have been called with the actual PruneInterval
	var period time.Duration
	select {
	case period = <-fakeTimer.period:
	case <-time.After(coretesting.LongWait):
		c.Fatal("timed out waiting for period reset by pruner")
	}
	c.Assert(period, gc.Equals, coretesting.ShortWait)
}