From cf06605fa901ed9a0a996d372f180d58f9bb2347 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 13 Jun 2024 23:58:06 +0200 Subject: [PATCH] Fix archive host names --- cmd/soroban-rpc/internal/test/archive_test.go | 18 +++++-- .../internal/test/docker-compose.rpc.yml | 3 -- .../internal/test/docker-compose.yml | 1 - cmd/soroban-rpc/internal/test/integration.go | 51 +++++++------------ 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/cmd/soroban-rpc/internal/test/archive_test.go b/cmd/soroban-rpc/internal/test/archive_test.go index d0aebe49..eaa4578e 100644 --- a/cmd/soroban-rpc/internal/test/archive_test.go +++ b/cmd/soroban-rpc/internal/test/archive_test.go @@ -1,7 +1,12 @@ package test import ( + "net" "net/http" + "net/http/httptest" + "net/http/httputil" + "net/url" + "strconv" "sync" "testing" @@ -9,12 +14,19 @@ import ( ) func TestArchiveUserAgent(t *testing.T) { + archiveHost := net.JoinHostPort("localhost", strconv.Itoa(StellarCoreArchivePort)) + proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: archiveHost}) userAgents := sync.Map{} + historyArchiveProxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + userAgents.Store(r.Header["User-Agent"][0], "") + proxy.ServeHTTP(w, r) + })) + defer historyArchiveProxy.Close() + cfg := &TestConfig{ - historyArchiveProxyCallback: func(r *http.Request) { - userAgents.Store(r.Header["User-Agent"][0], "") - }, + HistoryArchiveURL: historyArchiveProxy.URL, } + NewTest(t, cfg) _, ok := userAgents.Load("soroban-rpc/0.0.0") diff --git a/cmd/soroban-rpc/internal/test/docker-compose.rpc.yml b/cmd/soroban-rpc/internal/test/docker-compose.rpc.yml index 46c560ae..ae540528 100644 --- a/cmd/soroban-rpc/internal/test/docker-compose.rpc.yml +++ b/cmd/soroban-rpc/internal/test/docker-compose.rpc.yml @@ -1,4 +1,3 @@ -version: '3' services: rpc: platform: linux/amd64 @@ -13,5 +12,3 @@ services: - ${RPC_CONFIG_MOUNT_DIR}/stellar-core-integration-tests.cfg:/stellar-core.cfg - ${RPC_CONFIG_MOUNT_DIR}/soroban-rpc.config:/soroban-rpc.config - ${RPC_SQLITE_MOUNT_DIR}:/db/ - extra_hosts: - - "host.docker.internal:host-gateway" diff --git a/cmd/soroban-rpc/internal/test/docker-compose.yml b/cmd/soroban-rpc/internal/test/docker-compose.yml index 4b246f7b..cf3e7b0d 100644 --- a/cmd/soroban-rpc/internal/test/docker-compose.yml +++ b/cmd/soroban-rpc/internal/test/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' services: core-postgres: image: postgres:9.6.17-alpine diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index 9594d560..0ed331c3 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -4,11 +4,6 @@ import ( "bytes" "context" "fmt" - "net" - "net/http" - "net/http/httptest" - "net/http/httputil" - "net/url" "os" "os/exec" "os/signal" @@ -39,7 +34,7 @@ const ( StandaloneNetworkPassphrase = "Standalone Network ; February 2017" MaxSupportedProtocolVersion = 21 stellarCorePort = 11626 - stellarCoreArchiveHost = "localhost:1570" + StellarCoreArchivePort = 1570 goModFile = "go.mod" friendbotURL = "http://localhost:8000/friendbot" @@ -51,11 +46,11 @@ const ( ) type TestConfig struct { - historyArchiveProxyCallback func(*http.Request) - ProtocolVersion uint32 + ProtocolVersion uint32 // Run a previously released version of RPC (in a container) instead of the current version UseReleasedRPCVersion string UseSQLitePath string + HistoryArchiveURL string } type Test struct { @@ -65,21 +60,20 @@ type Test struct { protocolVersion uint32 + historyArchiveURL string + rpcContainerVersion string rpcContainerConfigMountDir string rpcContainerSQLiteMountDir string + rpcClient *jrpc2.Client daemon *daemon.Daemon - historyArchiveProxy *httptest.Server - historyArchiveProxyCallback func(*http.Request) - coreClient *stellarcore.Client masterAccount txnbuild.Account shutdownOnce sync.Once shutdownCalls []func() - rpcClient *jrpc2.Client } func NewTest(t *testing.T, cfg *TestConfig) *Test { @@ -98,8 +92,8 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { sqlLitePath := "" if cfg != nil { + i.historyArchiveURL = cfg.HistoryArchiveURL i.rpcContainerVersion = cfg.UseReleasedRPCVersion - i.historyArchiveProxyCallback = cfg.historyArchiveProxyCallback i.protocolVersion = cfg.ProtocolVersion sqlLitePath = cfg.UseSQLitePath } @@ -109,15 +103,6 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { i.protocolVersion = GetCoreMaxSupportedProtocol() } - proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: stellarCoreArchiveHost}) - - i.historyArchiveProxy = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if i.historyArchiveProxyCallback != nil { - i.historyArchiveProxyCallback(r) - } - proxy.ServeHTTP(w, r) - })) - rpcCfg := i.getRPConfig(sqlLitePath) if i.rpcContainerVersion != "" { i.rpcContainerConfigMountDir = i.createRPCContainerMountDir(rpcCfg) @@ -192,19 +177,20 @@ func (i *Test) getRPConfig(sqlitePath string) map[string]string { // Out of the container default file captiveCoreConfigPath := path.Join(i.composePath, "captive-core-integration-tests.cfg") - archiveProxyURL := i.historyArchiveProxy.URL + archiveURL := fmt.Sprintf("http://localhost:%d", StellarCoreArchivePort) + if i.historyArchiveURL != "" { + archiveURL = i.historyArchiveURL + } else if i.rpcContainerVersion != "" { + // the archive needs to be accessed from the container + // where core is Core's hostname + archiveURL = fmt.Sprintf("http://core:%d", StellarCoreArchivePort) + } + stellarCoreURL := fmt.Sprintf("http://localhost:%d", stellarCorePort) bindHost := "localhost" if i.rpcContainerVersion != "" { // The file will be inside the container captiveCoreConfigPath = "/stellar-core.cfg" - // the archive needs to be accessed from the container - url, err := url.Parse(i.historyArchiveProxy.URL) - require.NoError(i.t, err) - _, port, err := net.SplitHostPort(url.Host) - require.NoError(i.t, err) - url.Host = net.JoinHostPort("host.docker.internal", port) - archiveProxyURL = url.String() // The container needs to listen on all interfaces, not just localhost bindHost = "0.0.0.0" // The container needs to use the sqlite mount point @@ -224,7 +210,7 @@ func (i *Test) getRPConfig(sqlitePath string) map[string]string { "STELLAR_CAPTIVE_CORE_HTTP_PORT": "0", "FRIENDBOT_URL": friendbotURL, "NETWORK_PASSPHRASE": StandaloneNetworkPassphrase, - "HISTORY_ARCHIVE_URLS": archiveProxyURL, + "HISTORY_ARCHIVE_URLS": archiveURL, "LOG_LEVEL": "debug", "DB_PATH": sqlitePath, "INGESTION_TIMEOUT": "10m", @@ -354,9 +340,6 @@ func (i *Test) prepareShutdownHandlers() { func() { close(done) i.StopRPC() - if i.historyArchiveProxy != nil { - i.historyArchiveProxy.Close() - } if i.rpcClient != nil { i.rpcClient.Close() }