[#1507] timer/test: Improve test coverage

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-11-20 10:53:33 +03:00 committed by Evgenii Stratonikov
parent 3042490340
commit 2e974f734c

View file

@ -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)