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")
|
|
|
|
|
2024-10-21 09:21:01 +00:00
|
|
|
require.True(t, srv.IsActive(context.Background()), "invalid IsActive result")
|
2024-10-21 13:27:28 +00:00
|
|
|
require.True(t, srv.IsAlphabet(context.Background()), "invalid IsAlphabet result")
|
2024-10-21 09:21:01 +00:00
|
|
|
require.Equal(t, 0, srv.InnerRingIndex(context.Background()), "invalid IR index")
|
|
|
|
require.Equal(t, 1, srv.InnerRingSize(context.Background()), "invalid IR index")
|
2024-10-21 13:27:28 +00:00
|
|
|
require.Equal(t, 0, srv.AlphabetIndex(context.Background()), "invalid alphabet index")
|
2023-04-25 11:54:01 +00:00
|
|
|
}
|