Browse Source

Test with Go 1.13 and 1.12 in CI (#1347)

* 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.
Martin Sucha 6 years ago
parent
commit
16cf9ea1b3
5 changed files with 11 additions and 5 deletions
  1. 1 1
      .travis.yml
  2. 1 1
      README.md
  3. 2 0
      cassandra_test.go
  4. 5 3
      common_test.go
  5. 2 0
      integration_test.go

+ 1 - 1
.travis.yml

@@ -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

+ 1 - 1
README.md

@@ -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.
 

+ 2 - 0
cassandra_test.go

@@ -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
@@ -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)

+ 5 - 3
common_test.go

@@ -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{
@@ -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

+ 2 - 0
integration_test.go

@@ -37,6 +37,7 @@ func TestAuthentication(t *testing.T) {
 }
 
 func TestGetHosts(t *testing.T) {
+	clusterHosts := getClusterHosts()
 	cluster := createCluster()
 	session := createSessionFromCluster(cluster, t)
 
@@ -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]