2023-04-25 11:54:01 +00:00
|
|
|
package innerring
|
|
|
|
|
|
|
|
import (
|
2024-10-21 08:30:31 +00:00
|
|
|
"context"
|
2023-04-25 11:54:01 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
control "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServerState(t *testing.T) {
|
|
|
|
keyStr := "03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae"
|
|
|
|
commiteeKeys, err := keys.NewPublicKeysFromStrings([]string{keyStr})
|
|
|
|
require.NoError(t, err, "convert string to commitee public keys failed")
|
|
|
|
cf := &testCommiteeFetcher{
|
|
|
|
keys: commiteeKeys,
|
|
|
|
}
|
|
|
|
|
|
|
|
irKeys, err := keys.NewPublicKeysFromStrings([]string{keyStr})
|
|
|
|
require.NoError(t, err, "convert string to IR public keys failed")
|
|
|
|
irf := &testIRFetcher{
|
|
|
|
keys: irKeys,
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := keys.NewPublicKeyFromString(keyStr)
|
|
|
|
require.NoError(t, err, "convert string to public key failed")
|
|
|
|
|
|
|
|
require.NoError(t, err, "failed to create morph client")
|
|
|
|
srv := &Server{
|
|
|
|
statusIndex: newInnerRingIndexer(cf, irf, key, time.Second),
|
|
|
|
morphClient: &client.Client{},
|
|
|
|
}
|
|
|
|
|
|
|
|
var epoch uint64 = 100
|
|
|
|
srv.SetEpochCounter(epoch)
|
|
|
|
require.Equal(t, epoch, srv.EpochCounter(), "invalid epoch counter")
|
|
|
|
|
|
|
|
var epochDuration uint64 = 15
|
|
|
|
srv.SetEpochDuration(epochDuration)
|
|
|
|
require.Equal(t, epochDuration, srv.EpochDuration(), "invalid epoch duration")
|
|
|
|
|
|
|
|
var healthStatus control.HealthStatus = control.HealthStatus_READY
|
2024-10-21 08:30:31 +00:00
|
|
|
srv.setHealthStatus(context.Background(), healthStatus)
|
2023-04-25 11:54:01 +00:00
|
|
|
require.Equal(t, healthStatus, srv.HealthStatus(), "invalid health status")
|
|
|
|
|
|
|
|
require.True(t, srv.IsActive(), "invalid IsActive result")
|
|
|
|
require.True(t, srv.IsAlphabet(), "invalid IsAlphabet result")
|
|
|
|
require.Equal(t, 0, srv.InnerRingIndex(), "invalid IR index")
|
|
|
|
require.Equal(t, 1, srv.InnerRingSize(), "invalid IR index")
|
|
|
|
require.Equal(t, 0, srv.AlphabetIndex(), "invalid alphabet index")
|
|
|
|
}
|