diff --git a/start b/start index f3a85e433..473bd3e05 100755 --- a/start +++ b/start @@ -78,6 +78,9 @@ function validate_after_copy_defaults() { function start() { echo "Starting Stellar Quickstart" + # Extract stellar-core version for horizon configuration + export STELLAR_CORE_VERSION=$(stellar-core version 2>/dev/null | head -1 | xargs) + echo "versions:" echo " quickstart: $REVISION" echo " xdr:" @@ -502,6 +505,7 @@ function init_horizon() { cat << EOF >> etc/horizon.env export CAPTIVE_CORE_CONFIG_PATH=$HORIZON_CAPTIVE_CORE_CFG export CAPTIVE_CORE_STORAGE_PATH=$HZHOME/captive-core +export STELLAR_CORE_VERSION=$STELLAR_CORE_VERSION EOF run_silent "chown-horizon" chown -R stellar:stellar . diff --git a/tests/test_core_version.go b/tests/test_core_version.go new file mode 100644 index 000000000..694c0207e --- /dev/null +++ b/tests/test_core_version.go @@ -0,0 +1,54 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + "os" + "time" +) + +const timeout = 3 * time.Minute + +type Root struct { + StellarCoreVersion string `json:"core_version"` +} + +func main() { + startTime := time.Now() + + for { + time.Sleep(5 * time.Second) + logLine("Waiting for Horizon to start and checking core_version") + + if time.Since(startTime) > timeout { + logLine("Timeout") + os.Exit(-1) + } + + resp, err := http.Get("http://localhost:8000") + if err != nil { + logLine(err) + continue + } + + var root Root + decoder := json.NewDecoder(resp.Body) + err = decoder.Decode(&root) + if err != nil { + logLine(err) + continue + } + + if root.StellarCoreVersion != "" { + logLine("SUCCESS: core_version is populated: " + root.StellarCoreVersion) + os.Exit(0) + } else { + logLine("core_version is still empty") + } + } +} + +func logLine(text interface{}) { + log.Println("\033[33;1m[core_version_test]\033[0m", text) +} \ No newline at end of file