Skip to content

Commit

Permalink
horizon: Clean up integration test variables (stellar#5288)
Browse files Browse the repository at this point in the history
All tests use captive-core so there is no need to specify it explicitly.

Soroban-rpc is enabled on a test by test based so there is no need to guard it
through its own env variable.
  • Loading branch information
2opremio authored Apr 21, 2024
1 parent 50804c5 commit 1042b62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 50 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ jobs:
run: |
docker pull "$PROTOCOL_${{ matrix.protocol-version }}_SOROBAN_RPC_DOCKER_IMG"
echo HORIZON_INTEGRATION_TESTS_SOROBAN_RPC_DOCKER_IMG="$PROTOCOL_${{ matrix.protocol-version }}_SOROBAN_RPC_DOCKER_IMG" >> $GITHUB_ENV
echo HORIZON_INTEGRATION_TESTS_ENABLE_SOROBAN_RPC=true >> $GITHUB_ENV
- name: Install and enable Captive Core
- name: Install core
run: |
# Workaround for https://github.com/actions/virtual-environments/issues/5245,
# libc++1-8 won't be installed if another version is installed (but apt won't give you a helpul
Expand All @@ -91,9 +90,7 @@ jobs:
sudo bash -c 'echo "deb https://apt.stellar.org focal unstable" > /etc/apt/sources.list.d/SDF-unstable.list'
sudo apt-get update && sudo apt-get install -y stellar-core="$PROTOCOL_${{ matrix.protocol-version }}_CORE_DEBIAN_PKG_VERSION"
echo "Using stellar core version $(stellar-core version)"
echo 'HORIZON_INTEGRATION_TESTS_ENABLE_CAPTIVE_CORE=true' >> $GITHUB_ENV
echo 'HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN=/usr/bin/stellar-core' >> $GITHUB_ENV
echo 'HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB=true' >> $GITHUB_ENV
- name: Build Horizon reproducible build
run: |
Expand Down
24 changes: 1 addition & 23 deletions services/horizon/internal/integration/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/spf13/cobra"

"github.com/stellar/go/services/horizon/internal/paths"
"github.com/stellar/go/services/horizon/internal/simplepath"

Expand Down Expand Up @@ -63,15 +64,6 @@ var (

// Ensures that BUCKET_DIR_PATH is not an allowed value for Captive Core.
func TestBucketDirDisallowed(t *testing.T) {
// This is a bit of a hacky workaround.
//
// In CI, we run our integration tests twice: once with Captive Core
// enabled, and once without. *These* tests only run with Captive Core
// configured properly (specifically, w/ the CAPTIVE_CORE_BIN envvar set).
if !integration.RunWithCaptiveCore {
t.Skip()
}

config := `BUCKET_DIR_PATH="/tmp"
` + SimpleCaptiveCoreToml

Expand Down Expand Up @@ -134,10 +126,6 @@ func TestEnvironmentPreserved(t *testing.T) {
// using NETWORK environment variables, history archive urls or network passphrase
// parameters are also set.
func TestInvalidNetworkParameters(t *testing.T) {
if !integration.RunWithCaptiveCore {
t.Skip()
}

var captiveCoreConfigErrMsg = integration.HorizonInitErrStr + ": error generating captive " +
"core configuration: invalid config: %s parameter not allowed with the %s parameter"
testCases := []struct {
Expand Down Expand Up @@ -191,9 +179,6 @@ func TestInvalidNetworkParameters(t *testing.T) {
// success. However, for "pubnet" or "testnet," we can not wait for Horizon to catch up,
// so we skip starting stellar-core containers.
func TestNetworkParameter(t *testing.T) {
if !integration.RunWithCaptiveCore {
t.Skip()
}
testCases := []struct {
networkValue string
networkPassphrase string
Expand Down Expand Up @@ -241,9 +226,6 @@ func TestNetworkParameter(t *testing.T) {
// success. However, for "pubnet" or "testnet," we can not wait for Horizon to catch up,
// so we skip starting stellar-core containers.
func TestNetworkEnvironmentVariable(t *testing.T) {
if !integration.RunWithCaptiveCore {
t.Skip()
}
testCases := []string{
horizon.StellarPubnet,
horizon.StellarTestnet,
Expand Down Expand Up @@ -277,10 +259,6 @@ func TestNetworkEnvironmentVariable(t *testing.T) {

// Ensures that the filesystem ends up in the correct state with Captive Core.
func TestCaptiveCoreConfigFilesystemState(t *testing.T) {
if !integration.RunWithCaptiveCore {
t.Skip() // explained above
}

confName, storagePath, cleanup := createCaptiveCoreConfig(SimpleCaptiveCoreToml)
defer cleanup()

Expand Down
35 changes: 12 additions & 23 deletions services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ const (
sorobanRPCPort = 8080
)

var (
HorizonInitErrStr = "cannot initialize Horizon"
RunWithCaptiveCore = os.Getenv("HORIZON_INTEGRATION_TESTS_ENABLE_CAPTIVE_CORE") != ""
RunWithSorobanRPC = os.Getenv("HORIZON_INTEGRATION_TESTS_ENABLE_SOROBAN_RPC") != ""
RunWithCaptiveCoreUseDB = os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_USE_DB") != ""
)
const HorizonInitErrStr = "cannot initialize Horizon"

type Config struct {
ProtocolVersion uint32
Expand Down Expand Up @@ -169,7 +164,7 @@ func NewTest(t *testing.T, config Config) *Test {
i.coreClient = &stellarcore.Client{URL: "http://localhost:" + strconv.Itoa(stellarCorePort)}
if !config.SkipCoreContainerCreation {
i.waitForCore()
if RunWithSorobanRPC && i.config.EnableSorobanRPC {
if i.config.EnableSorobanRPC {
i.runComposeCommand("up", "--detach", "--quiet-pull", "--no-color", "soroban-rpc")
i.waitForSorobanRPC()
}
Expand All @@ -187,21 +182,15 @@ func NewTest(t *testing.T, config Config) *Test {
}

func (i *Test) configureCaptiveCore() {
// We either test Captive Core through environment variables or through
// custom Horizon parameters.
if RunWithCaptiveCore {
composePath := findDockerComposePath()
i.coreConfig.binaryPath = os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN")
coreConfigFile := "captive-core-classic-integration-tests.cfg"
if i.config.ProtocolVersion >= ledgerbackend.MinimalSorobanProtocolSupport {
coreConfigFile = "captive-core-integration-tests.cfg"
}
i.coreConfig.configPath = filepath.Join(composePath, coreConfigFile)
i.coreConfig.storagePath = i.CurrentTest().TempDir()
if RunWithCaptiveCoreUseDB {
i.coreConfig.useDB = true
}
composePath := findDockerComposePath()
i.coreConfig.binaryPath = os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN")
coreConfigFile := "captive-core-classic-integration-tests.cfg"
if i.config.ProtocolVersion >= ledgerbackend.MinimalSorobanProtocolSupport {
coreConfigFile = "captive-core-integration-tests.cfg"
}
i.coreConfig.configPath = filepath.Join(composePath, coreConfigFile)
i.coreConfig.storagePath = i.CurrentTest().TempDir()
i.coreConfig.useDB = true

if value := i.getIngestParameter(
horizon.StellarCoreBinaryPathName,
Expand Down Expand Up @@ -233,7 +222,7 @@ func (i *Test) runComposeCommand(args ...string) {
integrationSorobanRPCYaml := filepath.Join(i.composePath, "docker-compose.integration-tests.soroban-rpc.yml")

cmdline := args
if RunWithSorobanRPC {
if i.config.EnableSorobanRPC {
cmdline = append([]string{"-f", integrationSorobanRPCYaml}, cmdline...)
}
cmdline = append([]string{"-f", integrationYaml}, cmdline...)
Expand Down Expand Up @@ -298,7 +287,7 @@ func (i *Test) prepareShutdownHandlers() {
if !i.config.SkipCoreContainerCreation {
i.runComposeCommand("rm", "-fvs", "core")
i.runComposeCommand("rm", "-fvs", "core-postgres")
if os.Getenv("HORIZON_INTEGRATION_TESTS_ENABLE_SOROBAN_RPC") != "" {
if i.config.EnableSorobanRPC {
i.runComposeCommand("logs", "soroban-rpc")
i.runComposeCommand("rm", "-fvs", "soroban-rpc")
}
Expand Down

0 comments on commit 1042b62

Please sign in to comment.