From 35370283ba1f6ee815102c33938407b4bd029c03 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 13 Feb 2024 10:08:49 +0300 Subject: [PATCH] [#948] adm: Move `TestNextPollInterval` to package `helper` Signed-off-by: Anton Nikiforov --- .../modules/morph/helper/initialize_test.go | 43 +++++++++++++++++++ .../morph/initialize/initialize_test.go | 35 --------------- 2 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 cmd/frostfs-adm/internal/modules/morph/helper/initialize_test.go diff --git a/cmd/frostfs-adm/internal/modules/morph/helper/initialize_test.go b/cmd/frostfs-adm/internal/modules/morph/helper/initialize_test.go new file mode 100644 index 000000000..f3ce42f51 --- /dev/null +++ b/cmd/frostfs-adm/internal/modules/morph/helper/initialize_test.go @@ -0,0 +1,43 @@ +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) +} diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go index a05e995a7..e39c7356f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize/initialize_test.go @@ -153,38 +153,3 @@ func setTestCredentials(v *viper.Viper, size int) { } v.Set("credentials.contract", constants.TestContractPassword) } - -func TestNextPollInterval(t *testing.T) { - var pollInterval time.Duration - var iteration int - - pollInterval, hasChanged := helper.NextPollInterval(iteration, pollInterval) - require.True(t, hasChanged) - require.Equal(t, time.Second, pollInterval) - - iteration = 4 - pollInterval, hasChanged = helper.NextPollInterval(iteration, pollInterval) - require.False(t, hasChanged) - require.Equal(t, time.Second, pollInterval) - - iteration = 5 - pollInterval, hasChanged = helper.NextPollInterval(iteration, pollInterval) - require.True(t, hasChanged) - require.Equal(t, 2*time.Second, pollInterval) - - iteration = 10 - pollInterval, hasChanged = helper.NextPollInterval(iteration, pollInterval) - require.True(t, hasChanged) - require.Equal(t, 4*time.Second, pollInterval) - - iteration = 20 - pollInterval = 32 * time.Second - pollInterval, hasChanged = helper.NextPollInterval(iteration, pollInterval) - require.True(t, hasChanged) // from 32s to 16s - require.Equal(t, 16*time.Second, pollInterval) - - pollInterval = 16 * time.Second - pollInterval, hasChanged = helper.NextPollInterval(iteration, pollInterval) - require.False(t, hasChanged) - require.Equal(t, 16*time.Second, pollInterval) -}