示例#1
0
func (s *timerSuite) TestResetAndStart(c *gc.C) {
	s.timer.Reset()
	currentDuration := utils.ExposeBackoffTimerDuration(s.timer)
	c.Assert(currentDuration, gc.Equals, s.min)

	// These variables are used to track the number
	// of afterFuncCalls(signalCallsNo) and the number
	// of Stop calls(resetStopCallsNo + signalCallsNo)
	resetStopCallsNo := 0
	signalCallsNo := 0

	signalCallsNo++
	s.timer.Start()
	s.testStart(c, 1, 1)

	resetStopCallsNo++
	s.timer.Reset()
	s.checkStopCalls(c, resetStopCallsNo+signalCallsNo-1)
	currentDuration = utils.ExposeBackoffTimerDuration(s.timer)
	c.Assert(currentDuration, gc.Equals, s.min)

	for i := 1; i < 200; i++ {
		signalCallsNo++
		s.timer.Start()
		s.testStart(c, int64(signalCallsNo), int64(i))
		s.checkStopCalls(c, resetStopCallsNo+signalCallsNo-1)
	}

	resetStopCallsNo++
	s.timer.Reset()
	s.checkStopCalls(c, signalCallsNo+resetStopCallsNo-1)

	for i := 1; i < 100; i++ {
		signalCallsNo++
		s.timer.Start()
		s.testStart(c, int64(signalCallsNo), int64(i))
		s.checkStopCalls(c, resetStopCallsNo+signalCallsNo-1)
	}

	resetStopCallsNo++
	s.timer.Reset()
	s.checkStopCalls(c, signalCallsNo+resetStopCallsNo-1)
}
示例#2
0
func (s *timerSuite) testStart(c *gc.C, afterFuncCalls int64, durationFactor int64) {
	c.Assert(s.afterFuncCalls, gc.Equals, afterFuncCalls)
	c.Logf("iteration %d", afterFuncCalls)
	expectedDuration := time.Duration(math.Pow(float64(s.factor), float64(durationFactor))) * s.min
	if expectedDuration > s.max || expectedDuration <= 0 {
		expectedDuration = s.max
	}
	currentDuration := utils.ExposeBackoffTimerDuration(s.timer)
	c.Assert(currentDuration, gc.Equals, expectedDuration)
}
示例#3
0
func (s *timerSuite) TestResetNoStart(c *gc.C) {
	s.timer.Reset()
	currentDuration := utils.ExposeBackoffTimerDuration(s.timer)
	c.Assert(currentDuration, gc.Equals, s.min)
}