mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
* Fix misleading log msg on shutdown gRPCServer.GracefulStop blocks until it has been shutdown. Logging "Initiated graceful stop" after it has been completed is misleading. Names are added to the message to discern services. Also, a minimum test is added mainly to verify the change made with this commit. * Add changelog fragment file * Capitalize log messages * Update endtoend test for fixed log messages --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl>
92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
package rpc
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
mock "github.com/OffchainLabs/prysm/v6/beacon-chain/blockchain/testing"
|
|
mockExecution "github.com/OffchainLabs/prysm/v6/beacon-chain/execution/testing"
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/startup"
|
|
mockSync "github.com/OffchainLabs/prysm/v6/beacon-chain/sync/initial-sync/testing"
|
|
"github.com/OffchainLabs/prysm/v6/testing/assert"
|
|
"github.com/OffchainLabs/prysm/v6/testing/require"
|
|
"github.com/sirupsen/logrus"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func init() {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetOutput(io.Discard)
|
|
}
|
|
|
|
func TestLifecycle_OK(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
chainService := &mock.ChainService{
|
|
Genesis: time.Now(),
|
|
}
|
|
rpcService := NewService(t.Context(), &Config{
|
|
Port: "7348",
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
BlockReceiver: chainService,
|
|
AttestationReceiver: chainService,
|
|
HeadFetcher: chainService,
|
|
GenesisTimeFetcher: chainService,
|
|
ExecutionChainService: &mockExecution.Chain{},
|
|
StateNotifier: chainService.StateNotifier(),
|
|
Router: http.NewServeMux(),
|
|
ClockWaiter: startup.NewClockSynchronizer(),
|
|
})
|
|
|
|
rpcService.Start()
|
|
|
|
require.LogsContain(t, hook, "Beacon chain gRPC server listening")
|
|
assert.NoError(t, rpcService.Stop())
|
|
require.LogsContain(t, hook, "Completed graceful stop of beacon-chain gRPC server")
|
|
}
|
|
|
|
func TestStatus_CredentialError(t *testing.T) {
|
|
credentialErr := errors.New("credentialError")
|
|
s := &Service{
|
|
cfg: &Config{SyncService: &mockSync.Sync{IsSyncing: false},
|
|
OptimisticModeFetcher: &mock.ChainService{Optimistic: false}},
|
|
credentialError: credentialErr,
|
|
}
|
|
|
|
assert.ErrorContains(t, s.credentialError.Error(), s.Status())
|
|
}
|
|
|
|
func TestStatus_Optimistic(t *testing.T) {
|
|
s := &Service{
|
|
cfg: &Config{SyncService: &mockSync.Sync{IsSyncing: false},
|
|
OptimisticModeFetcher: &mock.ChainService{Optimistic: true}},
|
|
}
|
|
|
|
assert.ErrorContains(t, "service is optimistic", s.Status())
|
|
}
|
|
|
|
func TestRPC_InsecureEndpoint(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
chainService := &mock.ChainService{Genesis: time.Now()}
|
|
rpcService := NewService(t.Context(), &Config{
|
|
Port: "7777",
|
|
SyncService: &mockSync.Sync{IsSyncing: false},
|
|
BlockReceiver: chainService,
|
|
GenesisTimeFetcher: chainService,
|
|
AttestationReceiver: chainService,
|
|
HeadFetcher: chainService,
|
|
ExecutionChainService: &mockExecution.Chain{},
|
|
StateNotifier: chainService.StateNotifier(),
|
|
Router: http.NewServeMux(),
|
|
ClockWaiter: startup.NewClockSynchronizer(),
|
|
})
|
|
|
|
rpcService.Start()
|
|
|
|
require.LogsContain(t, hook, "Beacon chain gRPC server listening")
|
|
require.LogsContain(t, hook, "You are using an insecure gRPC server")
|
|
assert.NoError(t, rpcService.Stop())
|
|
}
|