Skip to content

Commit

Permalink
services/horizon: Move integration tests away from stellar/quickstart. (
Browse files Browse the repository at this point in the history
#3143)

* Get tests to use Docker Compose over stellar/quickstart
* Handle captive-core runs a little more graciously
* Add manual close configuration for docker-compose
* Simplify tests by using dedicated yaml config for integration tests
* Clear ledgerstate between test runs

Co-authored-by: Tamir Sen <[email protected]>
Co-authored-by: tamirms <[email protected]>
Co-authored-by: Bartek Nowotarski <[email protected]>
  • Loading branch information
4 people authored Nov 5, 2020
1 parent 9bf59df commit 38aec89
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 340 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ commands:
# Pulling the image helps with test running time
command: |
cd ~/go/src/github.com/stellar/go
docker pull stellar/quickstart:testing
<<# parameters.enable-captive-core >>HORIZON_INTEGRATION_ENABLE_CAPTIVE_CORE=true<</ parameters.enable-captive-core >> go test -timeout 25m -v ./services/horizon/internal/integration/...
#-----------------------------------------------------------------------------#
Expand Down Expand Up @@ -433,6 +432,9 @@ jobs:
command: |
echo "export HORIZON_INTEGRATION_TESTS=true" >> $BASH_ENV
echo "export HORIZON_BIN_DIR=~/go/src/github.com/stellar/go" >> $BASH_ENV
- run:
name: Pull latest Stellar Core image
command: docker pull stellar/stellar-core
- install_golang
- build_horizon
# run the integration tests ...
Expand Down
26 changes: 26 additions & 0 deletions clients/stellarcore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"

Expand All @@ -26,6 +27,31 @@ type Client struct {
URL string
}

// Upgrade upgrades the protocol version running on the stellar core instance
func (c *Client) Upgrade(ctx context.Context, version int) error {
queryParams := url.Values{}
queryParams.Add("mode", "set")
queryParams.Add("upgradetime", "1970-01-01T00:00:00Z")
queryParams.Add("protocolversion", strconv.Itoa(version))

req, err := c.simpleGet(ctx, "upgrades", queryParams)
if err != nil {
return errors.Wrap(err, "failed to create request")
}

hresp, err := c.http().Do(req)
if err != nil {
return errors.Wrap(err, "http request errored")
}
defer hresp.Body.Close()

if !(hresp.StatusCode >= 200 && hresp.StatusCode < 300) {
return errors.New("http request failed with non-200 status code")
}

return nil
}

// Info calls the `info` command on the connected stellar core and returns the
// provided response
func (c *Client) Info(ctx context.Context) (resp *proto.InfoResponse, err error) {
Expand Down
5 changes: 0 additions & 5 deletions go.list
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
github.com/client9/misspell v0.3.4
github.com/davecgh/go-spew v1.1.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0
github.com/eapache/go-resiliency v1.1.0
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21
github.com/eapache/queue v1.1.0
Expand Down Expand Up @@ -85,7 +81,6 @@ github.com/moul/http2curl v0.0.0-20161031194548-4e24498b31db
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
github.com/opencontainers/go-digest v1.0.0
github.com/opentracing/opentracing-go v1.1.0
github.com/openzipkin/zipkin-go v0.1.6
github.com/pierrec/lz4 v2.0.5+incompatible
Expand Down
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ require (
github.com/asaskevich/govalidator v0.0.0-20180319081651-7d2e70ef918f
github.com/aws/aws-sdk-go v1.25.25
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/fatih/structs v1.0.0 // indirect
github.com/gavv/monotime v0.0.0-20161010190848-47d58efa6955 // indirect
Expand Down Expand Up @@ -51,7 +47,6 @@ require (
github.com/moul/http2curl v0.0.0-20161031194548-4e24498b31db // indirect
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo=
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down Expand Up @@ -156,8 +148,6 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
25 changes: 25 additions & 0 deletions services/horizon/docker/docker-compose.integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3'
services:
core-postgres:
image: postgres:9.6.17-alpine
restart: on-failure
environment:
- POSTGRES_PASSWORD=mysecretpassword
- POSTGRES_DB=stellar
ports:
- "5641:5641"
command: ["-p", "5641"]
core:
image: stellar/stellar-core
depends_on:
- core-postgres
restart: on-failure
ports:
- "11625:11625"
- "11626:11626"
# add extra port for history archive server
- "1570:1570"
command: /start standalone
volumes:
- ./stellar-core-integration-tests.cfg:/stellar-core.cfg
- ./core-start.sh:/start
5 changes: 2 additions & 3 deletions services/horizon/docker/docker-compose.standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ services:
environment:
- HISTORY_ARCHIVE_URLS=http://host.docker.internal:1570
- NETWORK_PASSPHRASE=Standalone Network ; February 2017
# this container will invoke a request to upgrade stellar core to protocol 13
# this container will invoke a request to upgrade stellar core to protocol 15 (by default)
core-upgrade:
restart: on-failure
image: curlimages/curl:7.69.1
command: ["-v", "-f", "http://host.docker.internal:11626/upgrades?mode=set&upgradetime=1970-01-01T00:00:00Z&protocolversion=13"]
command: ["-v", "-f", "http://host.docker.internal:11626/upgrades?mode=set&upgradetime=1970-01-01T00:00:00Z&protocolversion=${PROTOCOL_VERSION:-15}"]
network_mode: '${NETWORK_MODE:-bridge}'

28 changes: 28 additions & 0 deletions services/horizon/docker/stellar-core-integration-tests.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# simple configuration for a standalone test "network"
# see stellar-core_example.cfg for a description of the configuration parameters

RUN_STANDALONE=false
MANUAL_CLOSE=true

NETWORK_PASSPHRASE="Standalone Network ; February 2017"

PEER_PORT=11625
HTTP_PORT=11626
PUBLIC_HTTP_PORT=true

NODE_SEED="SACJC372QBSSKJYTV5A7LWT4NXWHTQO6GHG4QDAVC2XDPX6CNNXFZ4JK"

NODE_IS_VALIDATOR=true
UNSAFE_QUORUM=true
FAILURE_SAFETY=0

DATABASE="postgresql://user=postgres password=mysecretpassword host=core-postgres port=5641 dbname=stellar"

[QUORUM_SET]
THRESHOLD_PERCENT=100
VALIDATORS=["GD5KD2KEZJIGTC63IGW6UMUSMVUVG5IHG64HUTFWCHVZH2N2IBOQN7PS"]

[HISTORY.vs]
get="cp history/vs/{0} {1}"
put="cp {0} history/vs/{1}"
mkdir="mkdir -p history/vs/{0}"
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestProtocol14StateVerifier(t *testing.T) {

// Reach the first checkpoint ledger
// Core will push to history archives *after* checkpoint ledger
itest.CloseCoreLedgersUntilSequence(firstCheckpoint + 1)
err = itest.CloseCoreLedgersUntilSequence(firstCheckpoint + 1)
assert.NoError(t, err)
for !itest.LedgerIngested(firstCheckpoint) {
time.Sleep(time.Second)
Expand All @@ -118,16 +118,17 @@ func TestProtocol14StateVerifier(t *testing.T) {
}

// Trigger state rebuild to check if ingesting from history archive works
itest.RunHorizonCLICommand("expingest", "trigger-state-rebuild")
err = itest.Horizon().HistoryQ().UpdateExpIngestVersion(0)
assert.NoError(t, err)

// Wait for the second checkpoint ledger and state rebuild
// Core will push to history archives *after* checkpoint ledger
itest.CloseCoreLedgersUntilSequence(secondCheckpoint + 1)
err = itest.CloseCoreLedgersUntilSequence(secondCheckpoint + 1)
assert.NoError(t, err)

// Wait for the third checkpoint ledger and state verification trigger
// Core will push to history archives *after* checkpoint ledger
itest.CloseCoreLedgersUntilSequence(thirdCheckpoint + 1)
err = itest.CloseCoreLedgersUntilSequence(thirdCheckpoint + 1)
assert.NoError(t, err)
for !itest.LedgerIngested(thirdCheckpoint) {
time.Sleep(time.Second)
Expand Down
10 changes: 5 additions & 5 deletions services/horizon/internal/integration/protocol14_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func TestHappyClaimableBalances(t *testing.T) {
a, b, c := keys[0], keys[1], keys[2]
accountA, accountB, accountC := accounts[0], accounts[1], accounts[2]

/*
* Each sub-test is completely self-contained: at the end of the test, we
* start with a clean slate for each account. This lets us check with
* equality for things like "number of operations," etc.
*/
//
// Each sub-test is completely self-contained: at the end of the test, we
// start with a clean slate for each account. This lets us check with
// equality for things like "number of operations," etc.
//

// We start simple: native asset, single destination, no predicate.
t.Run("Simple/Native", func(t *testing.T) {
Expand Down
Loading

0 comments on commit 38aec89

Please sign in to comment.