浏览代码

Merge pull request #633 from Zariel/increase-timeouts-tests

Integration test improvements
Chris Bannister 9 年之前
父节点
当前提交
8d541473ec
共有 6 个文件被更改,包括 68 次插入20 次删除
  1. 2 1
      cass1batch_test.go
  2. 4 0
      cassandra_test.go
  3. 13 6
      common_test.go
  4. 19 0
      host_source.go
  5. 21 0
      host_source_test.go
  6. 9 13
      integration.sh

+ 2 - 1
cass1batch_test.go

@@ -9,10 +9,11 @@ import (
 
 func TestProto1BatchInsert(t *testing.T) {
 	session := createSession(t)
+	defer session.Close()
+
 	if err := createTable(session, "CREATE TABLE gocql_test.large (id int primary key)"); err != nil {
 		t.Fatal(err)
 	}
-	defer session.Close()
 
 	begin := "BEGIN BATCH"
 	end := "APPLY BATCH"

+ 4 - 0
cassandra_test.go

@@ -2285,6 +2285,10 @@ func TestUnmarshallNestedTypes(t *testing.T) {
 }
 
 func TestSchemaReset(t *testing.T) {
+	if flagCassVersion.Major == 0 || (flagCassVersion.Before(2, 1, 3)) {
+		t.Skipf("skipping TestSchemaReset due to CASSANDRA-7910 in Cassandra <2.1.3 version=%v", flagCassVersion)
+	}
+
 	cluster := createCluster()
 	cluster.NumConns = 1
 

+ 13 - 6
common_test.go

@@ -22,10 +22,14 @@ var (
 	flagRunAuthTest  = flag.Bool("runauth", false, "Set to true to run authentication test")
 	flagCompressTest = flag.String("compressor", "", "compressor to use")
 	flagTimeout      = flag.Duration("gocql.timeout", 5*time.Second, "sets the connection `timeout` for all operations")
-	clusterHosts     []string
+
+	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)
@@ -48,14 +52,17 @@ var initOnce sync.Once
 func createTable(s *Session, table string) error {
 	// lets just be really sure
 	if err := s.control.awaitSchemaAgreement(); err != nil {
+		log.Printf("error waiting for schema agreement pre create table=%q err=%v\n", table, err)
 		return err
 	}
 
-	if err := s.control.query(table).Close(); err != nil {
+	if err := s.Query(table).RetryPolicy(nil).Exec(); err != nil {
+		log.Printf("error creating table table=%q err=%v\n", table, err)
 		return err
 	}
 
 	if err := s.control.awaitSchemaAgreement(); err != nil {
+		log.Printf("error waiting for schema agreement post create table=%q err=%v\n", table, err)
 		return err
 	}
 
@@ -88,17 +95,17 @@ func createCluster() *ClusterConfig {
 func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {
 	c := *cluster
 	c.Keyspace = "system"
-	c.Timeout = 20 * time.Second
+	c.Timeout = 30 * time.Second
 	session, err := c.CreateSession()
 	if err != nil {
-		tb.Fatal("createSession:", err)
+		panic(err)
 	}
 	defer session.Close()
 	defer log.Println("closing keyspace session")
 
 	err = createTable(session, `DROP KEYSPACE IF EXISTS `+keyspace)
 	if err != nil {
-		tb.Fatal(err)
+		panic(fmt.Sprintf("unable to drop keyspace: %v", err))
 	}
 
 	err = createTable(session, fmt.Sprintf(`CREATE KEYSPACE %s
@@ -108,7 +115,7 @@ func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {
 	}`, keyspace, *flagRF))
 
 	if err != nil {
-		tb.Fatal(err)
+		panic(fmt.Sprintf("unable to create keyspace: %v", err))
 	}
 }
 

+ 19 - 0
host_source.go

@@ -29,6 +29,14 @@ type cassVersion struct {
 	Major, Minor, Patch int
 }
 
+func (c *cassVersion) Set(v string) error {
+	if v == "" {
+		return nil
+	}
+
+	return c.UnmarshalCQL(nil, []byte(v))
+}
+
 func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error {
 	version := strings.TrimSuffix(string(data), "-SNAPSHOT")
 	version = strings.TrimPrefix(version, "v")
@@ -55,6 +63,17 @@ func (c *cassVersion) UnmarshalCQL(info TypeInfo, data []byte) error {
 	return nil
 }
 
+func (c cassVersion) Before(major, minor, patch int) bool {
+	if c.Major > major {
+		return true
+	} else if c.Minor > minor {
+		return true
+	} else if c.Patch > patch {
+		return true
+	}
+	return false
+}
+
 func (c cassVersion) String() string {
 	return fmt.Sprintf("v%d.%d.%d", c.Major, c.Minor, c.Patch)
 }

+ 21 - 0
host_source_test.go

@@ -21,3 +21,24 @@ func TestUnmarshalCassVersion(t *testing.T) {
 		}
 	}
 }
+
+func TestCassVersionBefore(t *testing.T) {
+	tests := [...]struct {
+		version             cassVersion
+		major, minor, patch int
+	}{
+		{cassVersion{1, 0, 0}, 0, 0, 0},
+		{cassVersion{0, 1, 0}, 0, 0, 0},
+		{cassVersion{0, 0, 1}, 0, 0, 0},
+
+		{cassVersion{1, 0, 0}, 0, 1, 0},
+		{cassVersion{0, 1, 0}, 0, 0, 1},
+	}
+
+	for i, test := range tests {
+		if !test.version.Before(test.major, test.minor, test.patch) {
+			t.Errorf("%d: expected v%d.%d.%d to be before %v", i, test.major, test.minor, test.patch, test.version)
+		}
+	}
+
+}

+ 9 - 13
integration.sh

@@ -59,25 +59,21 @@ function run_tests() {
 	ccm status
 	ccm node1 nodetool status
 
+	local args="-gocql.timeout=60s -runssl -proto=$proto -rf=3 -clusterSize=$clusterSize -autowait=2000ms -compressor=snappy -gocql.cversion=$version -cluster=$(ccm liveset) ./..."
+
 	if [ "$auth" = true ]
 	then
 		sleep 30s
-		go test -v . -timeout 15s -run=TestAuthentication -tags "integration gocql_debug" -runssl -runauth -proto=$proto -cluster=$(ccm liveset) -clusterSize=$clusterSize -autowait=1000ms
+		go test -run=TestAuthentication -tags "integration gocql_debug" -timeout=15s -v $args
 	else
+		sleep 1s
+		go test -tags "integration gocql_debug" -timeout=5m -v $args
 
-		go test -tags "integration gocql_debug" -timeout 10m -v -gocql.timeout=10s -runssl -proto=$proto -rf=3 -cluster=$(ccm liveset) -clusterSize=$clusterSize -autowait=2000ms -compressor=snappy ./...
-
-		if [ ${PIPESTATUS[0]} -ne 0 ]; then
-			echo "--- FAIL: ccm status follows:"
-			ccm status
-			ccm node1 nodetool status
-			ccm node1 showlog > status.log
-			cat status.log
-			echo "--- FAIL: Received a non-zero exit code from the go test execution, please investigate this"
-			exit 1
-		fi
+		ccm clear
+		ccm start
+		sleep 1s
 
-		go test -timeout 10m -tags "ccm gocql_debug" -v -gocql.timeout=10s -runssl -proto=$proto -rf=3 -cluster=$(ccm liveset) -clusterSize=$clusterSize -autowait=2000ms -compressor=snappy ./...
+		go test -tags "ccm gocql_debug" -timeout=5m -v $args
 	fi
 
 	ccm remove