From 6bc41a1c4df650f7aae7ae4486d56ad861c2fc57 Mon Sep 17 00:00:00 2001 From: Jacek Nykis Date: Thu, 17 Sep 2020 16:48:51 +0100 Subject: [PATCH 1/8] Override CircleCI builtin checkout command --- .circleci/config.yml | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 46275dbc08..00ea1299c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,6 +5,60 @@ version: 2.1 #----------------------------------------------------------------------------# commands: + checkout: + steps: + - run: + name: checkout + command: | + # Copy of the upstream checkout command with the following modification: + # 1. CIRCLE_REPOSITORY_URL is updated to use https rather than ssh + # 2. Removed ssh specific sections + + # Use https rather than ssh to clone public projects + CIRCLE_REPOSITORY_URL=${CIRCLE_REPOSITORY_URL/://} + CIRCLE_REPOSITORY_URL=${CIRCLE_REPOSITORY_URL/git@/https://} + + echo "Repository URL: ${CIRCLE_REPOSITORY_URL}" + + # Workaround old docker images with incorrect $HOME + # check https://github.com/docker/docker/issues/2968 for details + if [ "${HOME}" = "/" ] + then + export HOME=$(getent passwd $(id -un) | cut -d: -f6) + fi + + if [ -e ${CIRCLE_WORKING_DIRECTORY}/.git ] + then + cd ${CIRCLE_WORKING_DIRECTORY} + git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true + else + mkdir -p ${CIRCLE_WORKING_DIRECTORY} + cd ${CIRCLE_WORKING_DIRECTORY} + git clone "$CIRCLE_REPOSITORY_URL" . + fi + + if [ -n "$CIRCLE_TAG" ] + then + git fetch --force origin "refs/tags/${CIRCLE_TAG}" + else + # Ensure we pull PR refs as well as normal branches + git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pull/*" + git fetch --force --quiet origin + fi + + + if [ -n "$CIRCLE_TAG" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q "$CIRCLE_TAG" + elif [ -n "$CIRCLE_BRANCH" ] + then + git reset --hard "$CIRCLE_SHA1" + git checkout -q -B "$CIRCLE_BRANCH" + fi + + git reset --hard "$CIRCLE_SHA1" + # gofmt performs checks on the entire codebase to ensure everything is formated # with the gofmt tool. gofmt: From f173cf7bf4887381c7d96706da38f868ca744cb2 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Mon, 21 Sep 2020 12:51:12 -0700 Subject: [PATCH 2/8] protocols/horizon: fix trade aggregation paging token (#3043) ### What Change the paging token for trade aggregations (that isn't actually used) from being a single character that matches the unicode value of the timestamp, to being a string format of the timestamp integer. For timestamp: `64` Before: `"@"` After: `"64"` ### Why The paging token function isn't used for trade aggregations according to @tomerweller, but needed to be provided to satisfy the interface. The code there errors in Go 1.15 because Go 1.15 doesn't let you convert an integer to a string because in most cases, like the case here, it's a bug. To compile on Go 1.15 we either need to change this to convert to a rune first to tell the compiler this is intentional, or we need to fix this to convert the integer to a string correctly. This PR does the latter. --- protocols/horizon/main.go | 2 +- protocols/horizon/main_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/protocols/horizon/main.go b/protocols/horizon/main.go index 89b5b10b50..c8e5bd5a2c 100644 --- a/protocols/horizon/main.go +++ b/protocols/horizon/main.go @@ -416,7 +416,7 @@ type TradeAggregation struct { // PagingToken implementation for hal.Pageable. Not actually used func (res TradeAggregation) PagingToken() string { - return string(res.Timestamp) + return strconv.FormatInt(res.Timestamp, 10) } // Transaction represents a single, successful transaction diff --git a/protocols/horizon/main_test.go b/protocols/horizon/main_test.go index 5c2c45594b..17f5f2ba10 100644 --- a/protocols/horizon/main_test.go +++ b/protocols/horizon/main_test.go @@ -233,3 +233,8 @@ func TestTransactionUnmarshalJSON(t *testing.T) { assert.Equal(t, int64(2500000000), parsedFeesAsInts.MaxFee) assert.Equal(t, int64(3000000000), parsedFeesAsInts.FeeCharged) } + +func TestTradeAggregation_PagingToken(t *testing.T) { + ta := TradeAggregation{Timestamp: 64} + assert.Equal(t, "64", ta.PagingToken()) +} From 63b9384ccb8c24ff98353290c7c86f1b16ce24dc Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Tue, 22 Sep 2020 10:44:18 -0700 Subject: [PATCH 3/8] clients/horizonclient: wrap errors relating to decoding responses (#2870) Wrap errors that occur when decoding the JSON response. So it is clear that if an error occurs parsing any part of the JSON we know the error occurred when parsing the response and not something else. I was getting an error using the Fund endpoint and it wasn't clear to me which part of the making the request and getting the response was erroring. --- clients/horizonclient/internal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/horizonclient/internal.go b/clients/horizonclient/internal.go index 6abc2a0993..b8b4b86d10 100644 --- a/clients/horizonclient/internal.go +++ b/clients/horizonclient/internal.go @@ -34,7 +34,7 @@ func decodeResponse(resp *http.Response, object interface{}, hc *Client) (err er err = decoder.Decode(&object) if err != nil { - return + return errors.Wrap(err, "error decoding response") } return } From f633ee082661c6fe34edeb56ecbe9abaa0022b92 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Tue, 22 Sep 2020 13:41:08 -0700 Subject: [PATCH 4/8] all: update supported go version to 1.14 and 1.15 (#3044) ### What Drop support for Go 1.13 from all modules, and update CI tests to run against Go 1.14 and 1.15. ### Why The code in this repo is intended to be supported on the latest two releases of Go. Go 1.15 was released on August 11th, 2020, and we should be running tests against this version and no longer need to run tests against Go 1.13. ### Known limitations The Go 1.15 docker images don't have a Debian Stretch variant and so I've used the Debian Buster variant and the artifact publishing is still using Go 1.14. This means we're continuing to publish artifacts built on Debian Stretch. If a Stretch variant of Go 1.15 docker images is released I'll update this, otherwise we have about 6 months until Go 1.16 is released and we'll need to start publishing with builds on Debian Buster. I've requested a Debian Stretch variant here: docker-library/golang#344. --- .circleci/config.yml | 39 ++++++++++--------- DEVELOPING.md | 2 +- README.md | 2 +- clients/horizonclient/CHANGELOG.md | 1 + clients/horizonclient/README.md | 2 +- exp/services/market-tracker/README.md | 2 +- services/federation/CHANGELOG.md | 1 + services/horizon/CHANGELOG.md | 4 ++ .../horizon/docker/verify-range/dependencies | 2 +- services/horizon/internal/docs/admin.md | 2 +- services/horizon/internal/docs/developing.md | 2 +- services/keystore/CHANGELOG.md | 1 + services/ticker/CHANGELOG.md | 1 + txnbuild/CHANGELOG.md | 4 ++ txnbuild/README.md | 2 +- 15 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 46275dbc08..09d5840cd3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -142,11 +142,11 @@ commands: #-----------------------------------------------------------------------------# jobs: - # check_code_1_14 performs code checks using Go 1.14. - check_code_1_14: + # check_code_1_15 performs code checks using Go 1.15. + check_code_1_15: working_directory: /go/src/github.com/stellar/go docker: - - image: circleci/golang:1.14-stretch + - image: circleci/golang:1.15 steps: - install_go_deps - check_go_deps @@ -156,11 +156,11 @@ jobs: - staticcheck - build_packages - # test_code_1_13 performs all package tests using Go 1.13. - test_code_1_13: + # test_code_1_14 performs all package tests using Go 1.14. + test_code_1_14: working_directory: /go/src/github.com/stellar/go docker: - - image: circleci/golang:1.13-stretch + - image: circleci/golang:1.14-stretch environment: GO111MODULE: "on" PGHOST: localhost @@ -176,11 +176,11 @@ jobs: - install_go_deps - test_packages - # test_code_1_13_postgres10 performs all package tests using Go 1.13 and Postgres 10. - test_code_1_13_postgres10: + # test_code_1_14_postgres10 performs all package tests using Go 1.14 and Postgres 10. + test_code_1_14_postgres10: working_directory: /go/src/github.com/stellar/go docker: - - image: circleci/golang:1.13-stretch + - image: circleci/golang:1.14-stretch environment: GO111MODULE: "on" PGHOST: localhost @@ -197,11 +197,11 @@ jobs: - install_go_deps - test_packages - # test_code_1_14 performs all package tests using Go 1.14. - test_code_1_14: + # test_code_1_15 performs all package tests using Go 1.15. + test_code_1_15: working_directory: /go/src/github.com/stellar/go docker: - - image: circleci/golang:1.14-stretch + - image: circleci/golang:1.15 environment: GO111MODULE: "on" PGHOST: localhost @@ -217,11 +217,11 @@ jobs: - install_go_deps - test_packages - # test_code_1_14 performs all package tests using Go 1.14 and Postgres 10. - test_code_1_14_postgres10: + # test_code_1_15 performs all package tests using Go 1.15 and Postgres 10. + test_code_1_15_postgres10: working_directory: /go/src/github.com/stellar/go docker: - - image: circleci/golang:1.14-stretch + - image: circleci/golang:1.15 environment: GO111MODULE: "on" PGHOST: localhost @@ -246,6 +246,9 @@ jobs: publish_artifacts: working_directory: /go/src/github.com/stellar/go docker: + # Artifacts are built on Go 1.14 because a Go 1.15 Docker image for + # Debian Stretch is currently not available. See + # https://github.com/docker-library/golang/issues/344. - image: circleci/golang:1.14-stretch steps: - check_deprecations @@ -317,11 +320,11 @@ workflows: check_code_and_test: jobs: - - check_code_1_14 - - test_code_1_13 - - test_code_1_13_postgres10 + - check_code_1_15 - test_code_1_14 - test_code_1_14_postgres10 + - test_code_1_15 + - test_code_1_15_postgres10 - publish_state_diff_docker_image: filters: branches: diff --git a/DEVELOPING.md b/DEVELOPING.md index e7980c0325..8897c9c12b 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -11,7 +11,7 @@ If you're making changes to Horizon, look for documentation in its [docs](servic ## Requirements To checkout, build, and run most tests these tools are required: - Git -- [Go 1.13 or Go 1.14](https://golang.org/dl) +- [Go 1.14 or Go 1.15](https://golang.org/dl) To run some tests these tools are also required: - PostgreSQL 9.6+ server running locally, or set [environment variables](https://www.postgresql.org/docs/9.6/libpq-envars.html) (e.g. `PGHOST`, etc) for alternative host. diff --git a/README.md b/README.md index 8cefc66a7d..2b9bd2f7ac 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ This repo contains various tools and services that you can use and deploy, as we ## Dependencies -This repository is officially supported on the last two releases of Go, which is currently Go 1.13 and Go 1.14. +This repository is officially supported on the last two releases of Go, which is currently Go 1.14 and Go 1.15. It depends on a [number of external dependencies](./go.mod), and uses Go [Modules](https://github.com/golang/go/wiki/Modules) to manage them. Running any `go` command will automatically download dependencies required for that operation. diff --git a/clients/horizonclient/CHANGELOG.md b/clients/horizonclient/CHANGELOG.md index 5211e24b43..d7e0af4908 100644 --- a/clients/horizonclient/CHANGELOG.md +++ b/clients/horizonclient/CHANGELOG.md @@ -8,6 +8,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/). * Remove JSON variant of `GET /metrics`, both in the server and client code. It's using Prometheus format by default now. * Add `NextAccountsPage`. * Fix `Fund` function that consistently errored. +* Dropped support for Go 1.13. ## [v3.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v3.0.0) - 2020-04-28 diff --git a/clients/horizonclient/README.md b/clients/horizonclient/README.md index 2c64094bd5..a1176fb3f7 100644 --- a/clients/horizonclient/README.md +++ b/clients/horizonclient/README.md @@ -12,7 +12,7 @@ This library is aimed at developers building Go applications that interact with * The [txnbuild API reference](https://godoc.org/github.com/stellar/go/txnbuild). ### Prerequisites -* Go 1.13 or greater +* Go 1.14 or greater * [Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies ### Installing diff --git a/exp/services/market-tracker/README.md b/exp/services/market-tracker/README.md index c96ff92fa4..01297c0fdb 100644 --- a/exp/services/market-tracker/README.md +++ b/exp/services/market-tracker/README.md @@ -7,7 +7,7 @@ To use this project, you will have to define the following in a `.env`: ## Running the project -This project was built using Go 1.13 and [Go Modules](https://blog.golang.org/using-go-modules) +This project was built using Go 1.14 and [Go Modules](https://blog.golang.org/using-go-modules) 1. From the monorepo root, navigate to the project: `cd exp/services/market-tracker` 2. Create a `config.json` file with the asset pairs to monitor and the refresh interval. A sample file is checked in at `config_sample.json` diff --git a/services/federation/CHANGELOG.md b/services/federation/CHANGELOG.md index 95da62e8b9..14436e3920 100644 --- a/services/federation/CHANGELOG.md +++ b/services/federation/CHANGELOG.md @@ -9,6 +9,7 @@ bumps. A breaking change will get clearly notified in this log. ## Unreleased * Dropped support for Go 1.12. +* Dropped support for Go 1.13. * Log User-Agent header in request logs. ## [v0.3.0] - 2019-11-20 diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index 81fe506a6a..07e8ab9ee4 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).x +## Unreleased + +* Dropped support for Go 1.13. + ## v1.8.2 * Fixed a bug which prevented Horizon from accepting TLS connections. diff --git a/services/horizon/docker/verify-range/dependencies b/services/horizon/docker/verify-range/dependencies index 8d6961584c..3480c4b0d8 100644 --- a/services/horizon/docker/verify-range/dependencies +++ b/services/horizon/docker/verify-range/dependencies @@ -22,4 +22,4 @@ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" git clone https://github.com/stellar/go.git stellar-go cd stellar-go -/usr/local/go/bin/go build -v ./services/horizon \ No newline at end of file +/usr/local/go/bin/go build -v ./services/horizon diff --git a/services/horizon/internal/docs/admin.md b/services/horizon/internal/docs/admin.md index 04af565d17..8c301e7de0 100644 --- a/services/horizon/internal/docs/admin.md +++ b/services/horizon/internal/docs/admin.md @@ -34,7 +34,7 @@ To test the installation, simply run `horizon --help` from a terminal. If the h Should you decide not to use one of our prebuilt releases, you may instead build Horizon from source. To do so, you need to install some developer tools: - A unix-like operating system with the common core commands (cp, tar, mkdir, bash, etc.) -- A compatible distribution of Go (Go 1.13 or later) +- A compatible distribution of Go (Go 1.14 or later) - [git](https://git-scm.com/) - [mercurial](https://www.mercurial-scm.org/) diff --git a/services/horizon/internal/docs/developing.md b/services/horizon/internal/docs/developing.md index 2b0478f449..a236c30b57 100644 --- a/services/horizon/internal/docs/developing.md +++ b/services/horizon/internal/docs/developing.md @@ -11,7 +11,7 @@ If you are just starting with Horizon and want to try it out, consider the [Quic Building Horizon requires the following developer tools: - A [Unix-like](https://en.wikipedia.org/wiki/Unix-like) operating system with the common core commands (cp, tar, mkdir, bash, etc.) -- Golang 1.13 or later +- Golang 1.14 or later - [git](https://git-scm.com/) (to check out Horizon's source code) - [mercurial](https://www.mercurial-scm.org/) (needed for `go-dep`) diff --git a/services/keystore/CHANGELOG.md b/services/keystore/CHANGELOG.md index b68ee1d061..9bac4c2a2b 100644 --- a/services/keystore/CHANGELOG.md +++ b/services/keystore/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased - Dropped support for Go 1.12. +* Dropped support for Go 1.13. ## [v1.2.0] - 2019-11-20 diff --git a/services/ticker/CHANGELOG.md b/services/ticker/CHANGELOG.md index cca7b1f190..3400061c18 100644 --- a/services/ticker/CHANGELOG.md +++ b/services/ticker/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased * Dropped support for Go 1.12. +* Dropped support for Go 1.13. ## [v1.2.0] - 2019-11-20 diff --git a/txnbuild/CHANGELOG.md b/txnbuild/CHANGELOG.md index 33af9fe620..f8d2c97e70 100644 --- a/txnbuild/CHANGELOG.md +++ b/txnbuild/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +* Dropped support for Go 1.13. + ## [v4.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v4.0.0) - 2020-08-31 ### Breaking changes diff --git a/txnbuild/README.md b/txnbuild/README.md index fc3d208500..9653c652b9 100644 --- a/txnbuild/README.md +++ b/txnbuild/README.md @@ -73,7 +73,7 @@ This library is aimed at developers building Go applications on top of the [Stel An easy-to-follow demonstration that exercises this SDK on the TestNet with actual accounts is also included! See the [Demo](#demo) section below. ### Prerequisites -* Go 1.13 or greater +* Go 1.14 or greater * [Modules](https://github.com/golang/go/wiki/Modules) to manage dependencies ### Installing From 0f49deba4707150190558eba107c8f5e191d994d Mon Sep 17 00:00:00 2001 From: Jacek Nykis Date: Thu, 24 Sep 2020 13:51:03 +0100 Subject: [PATCH 5/8] Improve circleci checkout workdir handling If CIRCLE_WORKING_DIRECTORY contains "~" character it's by default treated as string literal. This change ensures we expand paths before cloning code from git --- .circleci/config.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7dd208a048..d283f71c55 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ commands: - run: name: checkout command: | - # Copy of the upstream checkout command with the following modification: + # Copy of the upstream checkout command with the following modifications: # 1. CIRCLE_REPOSITORY_URL is updated to use https rather than ssh # 2. Removed ssh specific sections @@ -27,6 +27,8 @@ commands: export HOME=$(getent passwd $(id -un) | cut -d: -f6) fi + # Ensure ~ is expanded otherwise bash treats is as string literal + eval CIRCLE_WORKING_DIRECTORY=${CIRCLE_WORKING_DIRECTORY} if [ -e ${CIRCLE_WORKING_DIRECTORY}/.git ] then cd ${CIRCLE_WORKING_DIRECTORY} @@ -41,12 +43,12 @@ commands: then git fetch --force origin "refs/tags/${CIRCLE_TAG}" else - # Ensure we pull PR refs as well as normal branches + # By default "git fetch" only fetches refs/ + # Below ensures we also fetch PR refs git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pull/*" git fetch --force --quiet origin fi - if [ -n "$CIRCLE_TAG" ] then git reset --hard "$CIRCLE_SHA1" From fb84a374aa25b3ef78ba778375169a8b1a36cb7d Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Thu, 24 Sep 2020 12:32:46 -0700 Subject: [PATCH 6/8] exp/services/recoverysigner: do not set max idle db connections (#3052) ### What Remove the setting of the max idle database connections that was added in 3ad0378. ### Why To fix the issue that 3ad0378 was addressing we only needed to set the maximum number of total open connections. We set the max idle connections to the same value but sometimes keeping lots of idle connections open for long periods of time can cause issues if those idle connections get into a bad state. If a recoverysigner sees periods of low traffic its connections may sit idle for a long time. There's been no specific issue we've seen that is leading us to remove this, we just don't need it to be set to the same value. We could also make the idle connections a parameter, and if anyone needs that we can add it. --- exp/services/recoverysigner/internal/serve/serve.go | 1 - 1 file changed, 1 deletion(-) diff --git a/exp/services/recoverysigner/internal/serve/serve.go b/exp/services/recoverysigner/internal/serve/serve.go index 7e833de8b7..ffd7149482 100644 --- a/exp/services/recoverysigner/internal/serve/serve.go +++ b/exp/services/recoverysigner/internal/serve/serve.go @@ -105,7 +105,6 @@ func getHandlerDeps(opts Options) (handlerDeps, error) { return handlerDeps{}, errors.Wrap(err, "error parsing database url") } db.SetMaxOpenConns(opts.DatabaseMaxOpenConns) - db.SetMaxIdleConns(opts.DatabaseMaxOpenConns) err = db.Ping() if err != nil { From 32bb502eb383fb0ea3ac32907ea6fa3c398f567a Mon Sep 17 00:00:00 2001 From: Howard Tinghao Chen Date: Mon, 28 Sep 2020 11:32:20 -0400 Subject: [PATCH 7/8] support/http: add ReadTimeout, WriteTimeout, IdleTimeout configs (#3061) What This PR adds the ability to configure ReadTimeout, WriteTimout, IdleTimeout on the http server. Why We want to apply timeout to have a better control over our resources. A default http server comes with zero timeout. It's good that we have been setting the default ReadTimeout to 5 seconds. However, there was no way for the client of this package to set it to a different duration. And we are not currently setting WriteTimeout and IdleTimeout. --- support/http/main.go | 34 ++++++++++++++++++++++------------ support/http/main_test.go | 8 ++++++-- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/support/http/main.go b/support/http/main.go index f1b3c91a43..2ffdaf2a10 100644 --- a/support/http/main.go +++ b/support/http/main.go @@ -17,12 +17,12 @@ import ( "gopkg.in/tylerb/graceful.v1" ) -// DefaultListenAddr represents the default address and port on which a server +// defaultListenAddr represents the default address and port on which a server // will listen, provided it is not overridden by setting the `ListenAddr` field // on a `Config` struct. -const DefaultListenAddr = "0.0.0.0:8080" +const defaultListenAddr = "0.0.0.0:8080" -// DefaultShutdownGracePeriod represents the default time in which the running +// defaultShutdownGracePeriod represents the default time in which the running // process will allow outstanding http requests to complete before aborting // them. It will be used when a grace period of 0 is used, which normally // signifies "no timeout" to our graceful shutdown package. We choose not to @@ -30,7 +30,9 @@ const DefaultListenAddr = "0.0.0.0:8080" // or something if you need a timeout that is effectively "no timeout"; We // believe that most servers should use a sane timeout and prefer one for the // default configuration. -const DefaultShutdownGracePeriod = 10 * time.Second +const defaultShutdownGracePeriod = 10 * time.Second + +const defaultReadTimeout = 5 * time.Second // SimpleHTTPClientInterface helps mocking http.Client in tests type SimpleHTTPClientInterface interface { @@ -45,6 +47,9 @@ type Config struct { ListenAddr string TLS *config.TLS ShutdownGracePeriod time.Duration + ReadTimeout time.Duration + WriteTimeout time.Duration + IdleTimeout time.Duration OnStarting func() OnStopping func() OnStopped func() @@ -89,21 +94,26 @@ func setup(conf Config) *graceful.Server { } if conf.ListenAddr == "" { - conf.ListenAddr = DefaultListenAddr + conf.ListenAddr = defaultListenAddr + } + + if conf.ShutdownGracePeriod == time.Duration(0) { + conf.ShutdownGracePeriod = defaultShutdownGracePeriod } - timeout := DefaultShutdownGracePeriod - if conf.ShutdownGracePeriod != 0 { - timeout = conf.ShutdownGracePeriod + if conf.ReadTimeout == time.Duration(0) { + conf.ReadTimeout = defaultReadTimeout } return &graceful.Server{ - Timeout: timeout, + Timeout: conf.ShutdownGracePeriod, Server: &stdhttp.Server{ - Addr: conf.ListenAddr, - Handler: conf.Handler, - ReadTimeout: 5 * time.Second, + Addr: conf.ListenAddr, + Handler: conf.Handler, + ReadTimeout: conf.ReadTimeout, + WriteTimeout: conf.WriteTimeout, + IdleTimeout: conf.IdleTimeout, }, ShutdownInitiated: func() { diff --git a/support/http/main_test.go b/support/http/main_test.go index 655d05722b..3f41a29636 100644 --- a/support/http/main_test.go +++ b/support/http/main_test.go @@ -3,6 +3,7 @@ package http import ( stdhttp "net/http" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -21,6 +22,9 @@ func TestRun_setup(t *testing.T) { Handler: stdhttp.NotFoundHandler(), }) - assert.Equal(t, DefaultShutdownGracePeriod, srv.Timeout) - assert.Equal(t, DefaultListenAddr, srv.Server.Addr) + assert.Equal(t, defaultShutdownGracePeriod, srv.Timeout) + assert.Equal(t, defaultReadTimeout, srv.ReadTimeout) + assert.Equal(t, time.Duration(0), srv.WriteTimeout) + assert.Equal(t, time.Duration(0), srv.IdleTimeout) + assert.Equal(t, defaultListenAddr, srv.Server.Addr) } From ffa7e764fb46f243612e28bca0290052786d42af Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 29 Sep 2020 12:10:19 +0200 Subject: [PATCH 8/8] Remove redundant test (#2933) There is already a payment test in transaction_operation_wrapper_test.go --- .../processors/operations_processor_test.go | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/services/horizon/internal/expingest/processors/operations_processor_test.go b/services/horizon/internal/expingest/processors/operations_processor_test.go index 2bfccd16ea..a7b3ae0905 100644 --- a/services/horizon/internal/expingest/processors/operations_processor_test.go +++ b/services/horizon/internal/expingest/processors/operations_processor_test.go @@ -5,8 +5,6 @@ import ( "encoding/json" "testing" - "github.com/stretchr/testify/assert" - "github.com/stellar/go/exp/ingest/io" "github.com/stellar/go/services/horizon/internal/db2/history" "github.com/stellar/go/support/errors" @@ -142,36 +140,3 @@ func (s *OperationsProcessorTestSuiteLedger) TestExecFails() { s.Assert().Error(err) s.Assert().EqualError(err, "transient error") } - -func TestTransactionOperationWrapper_Details(t *testing.T) { - unmuxed := xdr.MustAddress("GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2") - muxed := xdr.MuxedAccount{ - Type: xdr.CryptoKeyTypeKeyTypeMuxedEd25519, - Med25519: &xdr.MuxedAccountMed25519{ - Id: 0xdeadbeefdeadbeef, - Ed25519: *unmuxed.Ed25519, - }, - } - tx := createTransaction(true, 1) - tx.Index = 1 - tx.Envelope.Operations()[0].Body = xdr.OperationBody{ - Type: xdr.OperationTypePayment, - PaymentOp: &xdr.PaymentOp{ - Destination: muxed, - Asset: xdr.Asset{Type: xdr.AssetTypeAssetTypeNative}, - Amount: 100, - }, - } - wrapper := transactionOperationWrapper{ - index: 1, - transaction: tx, - operation: tx.Envelope.Operations()[0], - ledgerSequence: uint32(56), - } - assert.Equal(t, wrapper.Details(), map[string]interface{}{ - "amount": "0.0000100", - "asset_type": "native", - "from": "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY", - "to": "GA5WBPYA5Y4WAEHXWR2UKO2UO4BUGHUQ74EUPKON2QHV4WRHOIRNKKH2", - }) -}