[#1507] timer/test: Improve test coverage
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
3042490340
commit
2e974f734c
1 changed files with 33 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package timer_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/timer"
|
||||
|
@ -48,6 +49,38 @@ func TestIRBlockTimer_Reset(t *testing.T) {
|
|||
require.Equal(t, baseCounter[0], baseCounter[1])
|
||||
}
|
||||
|
||||
func TestBlockTimer_ResetChangeDuration(t *testing.T) {
|
||||
var dur uint32 = 2
|
||||
var err error
|
||||
var counter int
|
||||
|
||||
bt := timer.NewBlockTimer(
|
||||
func() (uint32, error) { return dur, err },
|
||||
func() { counter++ })
|
||||
|
||||
require.NoError(t, bt.Reset())
|
||||
|
||||
tickN(bt, 2)
|
||||
require.Equal(t, 1, counter)
|
||||
|
||||
t.Run("return error", func(t *testing.T) {
|
||||
dur = 5
|
||||
err = errors.New("my awesome error")
|
||||
require.ErrorIs(t, bt.Reset(), err)
|
||||
|
||||
tickN(bt, 2)
|
||||
require.Equal(t, 2, counter)
|
||||
})
|
||||
t.Run("change duration", func(t *testing.T) {
|
||||
dur = 5
|
||||
err = nil
|
||||
require.NoError(t, bt.Reset())
|
||||
|
||||
tickN(bt, 5)
|
||||
require.Equal(t, 3, counter)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBlockTimer(t *testing.T) {
|
||||
blockDur := uint32(10)
|
||||
baseCallCounter := uint32(0)
|
||||
|
|
Loading…
Reference in a new issue