forked from TrueCloudLab/frostfs-node
43 lines
1.2 KiB
Go
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)
|
|
}
|