Skip to content

Commit

Permalink
Fix archive host names
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 13, 2024
1 parent 410fd0d commit cf06605
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 41 deletions.
18 changes: 15 additions & 3 deletions cmd/soroban-rpc/internal/test/archive_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
package test

import (
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
"strconv"
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

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")
Expand Down
3 changes: 0 additions & 3 deletions cmd/soroban-rpc/internal/test/docker-compose.rpc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
rpc:
platform: linux/amd64
Expand All @@ -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"
1 change: 0 additions & 1 deletion cmd/soroban-rpc/internal/test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
core-postgres:
image: postgres:9.6.17-alpine
Expand Down
51 changes: 17 additions & 34 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"bytes"
"context"
"fmt"
"net"
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit cf06605

Please sign in to comment.