frostfs-node/cmd/frostfs-adm/internal/modules/morph/helper/initialize_test.go
Anton Nikiforov 35370283ba
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m18s
DCO action / DCO (pull_request) Successful in 3m26s
Vulncheck / Vulncheck (pull_request) Successful in 3m23s
Build / Build Components (1.21) (pull_request) Successful in 3m58s
Tests and linters / Staticcheck (pull_request) Successful in 5m14s
Tests and linters / Lint (pull_request) Successful in 5m54s
Tests and linters / Tests (1.20) (pull_request) Successful in 9m24s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m33s
Tests and linters / Tests with -race (pull_request) Successful in 10m36s
[#948] adm: Move TestNextPollInterval to package helper
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2024-02-13 10:08:49 +03:00

43 lines
1.2 KiB
Go

package helper
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestNextPollInterval(t *testing.T) {
var pollInterval time.Duration
var iteration int
pollInterval, hasChanged := NextPollInterval(iteration, pollInterval)
require.True(t, hasChanged)
require.Equal(t, time.Second, pollInterval)
iteration = 4
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
require.False(t, hasChanged)
require.Equal(t, time.Second, pollInterval)
iteration = 5
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
require.True(t, hasChanged)
require.Equal(t, 2*time.Second, pollInterval)
iteration = 10
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
require.True(t, hasChanged)
require.Equal(t, 4*time.Second, pollInterval)
iteration = 20
pollInterval = 32 * time.Second
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
require.True(t, hasChanged) // from 32s to 16s
require.Equal(t, 16*time.Second, pollInterval)
pollInterval = 16 * time.Second
pollInterval, hasChanged = NextPollInterval(iteration, pollInterval)
require.False(t, hasChanged)
require.Equal(t, 16*time.Second, pollInterval)
}