Check if Phoenix server is up before starting tests
Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/repo Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/commit/53bcaa5c Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/tree/53bcaa5c Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/diff/53bcaa5c Branch: refs/heads/master Commit: 53bcaa5c946a3fbc8834b7b86231f4be75865f46 Parents: 019f9c6 Author: Francis Chuang <[email protected]> Authored: Mon Jul 10 14:06:47 2017 +1000 Committer: Julian Hyde <[email protected]> Committed: Thu Aug 10 18:47:12 2017 -0700 ---------------------------------------------------------------------- driver_go18_test.go | 2 +- driver_test.go | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/53bcaa5c/driver_go18_test.go ---------------------------------------------------------------------- diff --git a/driver_go18_test.go b/driver_go18_test.go index d5b7617..9f7955f 100644 --- a/driver_go18_test.go +++ b/driver_go18_test.go @@ -33,7 +33,7 @@ func (dbt *DBTest) mustQueryContext(ctx context.Context, query string, args ...i } func getContext() context.Context { - ctx, _ := context.WithTimeout(context.Background(), 2*time.Minute) + ctx, _ := context.WithTimeout(context.Background(), 4*time.Minute) return ctx } http://git-wip-us.apache.org/repos/asf/calcite-avatica-go/blob/53bcaa5c/driver_test.go ---------------------------------------------------------------------- diff --git a/driver_test.go b/driver_test.go index d7b56af..f51f40f 100644 --- a/driver_test.go +++ b/driver_test.go @@ -2,10 +2,12 @@ package avatica import ( "bytes" + "context" "crypto/sha256" "database/sql" "fmt" "io/ioutil" + "net/http" "os" "path/filepath" "strings" @@ -29,7 +31,28 @@ func init() { return defaultValue } - dsn = env("AVATICA_HOST", "http://phoenix-server:8765") + dsn = env("AVATICA_HOST", "http://phoenix:8765") + + // Wait for the phoenix server to be ready + ctx, _ := context.WithTimeout(context.Background(), 5*time.Minute) + ticker := time.NewTicker(2 * time.Second) + + for { + + select { + case <-ctx.Done(): + panic("Timed out while waiting for the phoenix server to be ready after 5 minutes.") + + case <-ticker.C: + resp, err := http.Get(dsn) + + if err == nil { + resp.Body.Close() + ticker.Stop() + return + } + } + } } func generateTableName() string {
