[#948] adm: Move `TestNextPollInterval` to package `helper`
Build / Build Components (1.20) (pull_request) Successful in 3m18s Details
DCO action / DCO (pull_request) Successful in 3m26s Details
Vulncheck / Vulncheck (pull_request) Successful in 3m23s Details
Build / Build Components (1.21) (pull_request) Successful in 3m58s Details
Tests and linters / Staticcheck (pull_request) Successful in 5m14s Details
Tests and linters / Lint (pull_request) Successful in 5m54s Details
Tests and linters / Tests (1.20) (pull_request) Successful in 9m24s Details
Tests and linters / Tests (1.21) (pull_request) Successful in 9m33s Details
Tests and linters / Tests with -race (pull_request) Successful in 10m36s Details

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
pull/950/head
Anton Nikiforov 2024-02-13 10:08:49 +03:00
parent 802192cfef
commit 35370283ba
2 changed files with 43 additions and 35 deletions

View File

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

View File

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