Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Test with Go 1.13 and 1.12 in CI (apache#1347)
Browse files Browse the repository at this point in the history
* Fix tests in Go 1.13

The flag.Parse() in common-test.go init() causes errors to be raised
since package testing no longer registers it's flags in its own init(),
but instead provides testing.Init().

One option to fix this is to call testing.Init() just before calling
flag.Parse(). However, testing.Init() is not available in older Go
releases so we'd need to create separate versions of init() based on
build tags.

Instead, we can remove the call to flag.Parse() altogether as it was
only used to set clusterHosts variable and we defer parsing of
clusterHosts to a time when tests are executed. This version of code
runs both on Go 1.12 and Go 1.13.

* Test with Go 1.13 and 1.12 in CI

As per the README: In general, the gocql team will focus on supporting
the current and previous versions of Go.
  • Loading branch information
martin-sucha authored and Zariel committed Sep 15, 2019
1 parent d63913d commit 16cf9ea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ env:
AUTH=false

go:
- 1.11.x
- 1.12.x
- 1.13.x

install:
- ./install_test_deps.sh $TRAVIS_REPO_SLUG
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ The following matrix shows the versions of Go and Cassandra that are tested with

Go/Cassandra | 2.1.x | 2.2.x | 3.x.x
-------------| -------| ------| ---------
1.11 | yes | yes | yes
1.12 | yes | yes | yes
1.13 | yes | yes | yes

Gocql has been tested in production against many different versions of Cassandra. Due to limits in our CI setup we only test against the latest 3 major releases, which coincide with the official support from the Apache project.

Expand Down
2 changes: 2 additions & 0 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,7 @@ func TestQueryInfo(t *testing.T) {
func TestPrepare_PreparedCacheEviction(t *testing.T) {
const maxPrepared = 4

clusterHosts := getClusterHosts()
host := clusterHosts[0]
cluster := createCluster()
cluster.MaxPreparedStmts = maxPrepared
Expand Down Expand Up @@ -2739,6 +2740,7 @@ func TestDiscoverViaProxy(t *testing.T) {
// that is infact a proxy it discovers the rest of the ring behind the proxy
// and does not store the proxies address as a host in its connection pool.
// See https://github.com/gocql/gocql/issues/481
clusterHosts := getClusterHosts()
proxy, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("unable to create proxy listener: %v", err)
Expand Down
8 changes: 5 additions & 3 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ var (
flagTimeout = flag.Duration("gocql.timeout", 5*time.Second, "sets the connection `timeout` for all operations")

flagCassVersion cassVersion
clusterHosts []string
)

func init() {
flag.Var(&flagCassVersion, "gocql.cversion", "the cassandra version being tested against")

flag.Parse()
clusterHosts = strings.Split(*flagCluster, ",")
log.SetFlags(log.Lshortfile | log.LstdFlags)
}

func getClusterHosts() []string {
return strings.Split(*flagCluster, ",")
}

func addSslOptions(cluster *ClusterConfig) *ClusterConfig {
if *flagRunSslTest {
cluster.SslOpts = &SslOptions{
Expand Down Expand Up @@ -72,6 +73,7 @@ func createTable(s *Session, table string) error {
}

func createCluster(opts ...func(*ClusterConfig)) *ClusterConfig {
clusterHosts := getClusterHosts()
cluster := NewCluster(clusterHosts...)
cluster.ProtoVersion = *flagProto
cluster.CQLVersion = *flagCQL
Expand Down
2 changes: 2 additions & 0 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestAuthentication(t *testing.T) {
}

func TestGetHosts(t *testing.T) {
clusterHosts := getClusterHosts()
cluster := createCluster()
session := createSessionFromCluster(cluster, t)

Expand All @@ -49,6 +50,7 @@ func TestGetHosts(t *testing.T) {

//TestRingDiscovery makes sure that you can autodiscover other cluster members when you seed a cluster config with just one node
func TestRingDiscovery(t *testing.T) {
clusterHosts := getClusterHosts()
cluster := createCluster()
cluster.Hosts = clusterHosts[:1]

Expand Down

0 comments on commit 16cf9ea

Please sign in to comment.