feat(proxyd): add smoke test (#9875)
This commit is contained in:
parent
fcf6e3323d
commit
94c236b467
@ -28,8 +28,7 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
// Set up logger with a default INFO level in case we fail to parse flags.
|
// Set up logger with a default INFO level in case we fail to parse flags.
|
||||||
// Otherwise the final critical log won't show what the parsing error was.
|
// Otherwise the final critical log won't show what the parsing error was.
|
||||||
log.SetDefault(log.NewLogger(slog.NewJSONHandler(
|
proxyd.SetLogLevel(slog.LevelInfo)
|
||||||
os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})))
|
|
||||||
|
|
||||||
log.Info("starting proxyd", "version", GitVersion, "commit", GitCommit, "date", GitDate)
|
log.Info("starting proxyd", "version", GitVersion, "commit", GitCommit, "date", GitDate)
|
||||||
|
|
||||||
@ -50,8 +49,7 @@ func main() {
|
|||||||
log.Warn("invalid server.log_level set: " + config.Server.LogLevel)
|
log.Warn("invalid server.log_level set: " + config.Server.LogLevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.SetDefault(log.NewLogger(slog.NewJSONHandler(
|
proxyd.SetLogLevel(logLevel)
|
||||||
os.Stdout, &slog.HandlerOptions{Level: logLevel})))
|
|
||||||
|
|
||||||
if config.Server.EnablePprof {
|
if config.Server.EnablePprof {
|
||||||
log.Info("starting pprof", "addr", "0.0.0.0", "port", "6060")
|
log.Info("starting pprof", "addr", "0.0.0.0", "port", "6060")
|
||||||
|
51
proxyd/proxyd/integration_tests/smoke_test.go
Normal file
51
proxyd/proxyd/integration_tests/smoke_test.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package integration_tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum-optimism/optimism/proxyd"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitProxyd(t *testing.T) {
|
||||||
|
goodBackend := NewMockBackend(BatchedResponseHandler(200, goodResponse))
|
||||||
|
defer goodBackend.Close()
|
||||||
|
|
||||||
|
require.NoError(t, os.Setenv("GOOD_BACKEND_RPC_URL", goodBackend.URL()))
|
||||||
|
|
||||||
|
config := ReadConfig("smoke")
|
||||||
|
|
||||||
|
sysStdOut := os.Stdout
|
||||||
|
r, w, err := os.Pipe()
|
||||||
|
require.NoError(t, err)
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
|
proxyd.SetLogLevel(log.LevelInfo)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
w.Close()
|
||||||
|
out, _ := io.ReadAll(r)
|
||||||
|
require.True(t, strings.Contains(string(out), "started proxyd"))
|
||||||
|
require.True(t, strings.Contains(string(out), "shutting down proxyd"))
|
||||||
|
fmt.Println(string(out))
|
||||||
|
os.Stdout = sysStdOut
|
||||||
|
}()
|
||||||
|
|
||||||
|
_, shutdown, err := proxyd.Start(config)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer shutdown()
|
||||||
|
|
||||||
|
t.Run("initialization", func(t *testing.T) {
|
||||||
|
client := NewProxydClient("http://127.0.0.1:8545")
|
||||||
|
res, code, err := client.SendRPC(ethChainID, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 200, code)
|
||||||
|
require.NotNil(t, res)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
18
proxyd/proxyd/integration_tests/testdata/smoke.toml
vendored
Normal file
18
proxyd/proxyd/integration_tests/testdata/smoke.toml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[server]
|
||||||
|
rpc_port = 8545
|
||||||
|
|
||||||
|
[backend]
|
||||||
|
response_timeout_seconds = 1
|
||||||
|
|
||||||
|
[backends]
|
||||||
|
[backends.good]
|
||||||
|
rpc_url = "$GOOD_BACKEND_RPC_URL"
|
||||||
|
ws_url = "$GOOD_BACKEND_RPC_URL"
|
||||||
|
|
||||||
|
[backend_groups]
|
||||||
|
[backend_groups.main]
|
||||||
|
backends = ["good"]
|
||||||
|
|
||||||
|
[rpc_method_mappings]
|
||||||
|
eth_chainId = "main"
|
||||||
|
|
@ -13,9 +13,15 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
|
"golang.org/x/exp/slog"
|
||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SetLogLevel(logLevel slog.Leveler) {
|
||||||
|
log.SetDefault(log.NewLogger(slog.NewJSONHandler(
|
||||||
|
os.Stdout, &slog.HandlerOptions{Level: logLevel})))
|
||||||
|
}
|
||||||
|
|
||||||
func Start(config *Config) (*Server, func(), error) {
|
func Start(config *Config) (*Server, func(), error) {
|
||||||
if len(config.Backends) == 0 {
|
if len(config.Backends) == 0 {
|
||||||
return nil, nil, errors.New("must define at least one backend")
|
return nil, nil, errors.New("must define at least one backend")
|
||||||
|
Loading…
Reference in New Issue
Block a user