Browse Source

Merge pull request #611 from Zariel/test-flakes

Test flakes
Chris Bannister 10 years ago
parent
commit
0ceb8f3711
2 changed files with 23 additions and 4 deletions
  1. 6 2
      cassandra_test.go
  2. 17 2
      conn_test.go

+ 6 - 2
cassandra_test.go

@@ -1090,9 +1090,13 @@ func TestQueryInfo(t *testing.T) {
 
 //TestPreparedCacheEviction will make sure that the cache size is maintained
 func TestPreparedCacheEviction(t *testing.T) {
-	session := createSession(t)
+	const maxPrepared = 4
+	cluster := createCluster()
+	cluster.MaxPreparedStmts = maxPrepared
+	cluster.Events.DisableSchemaEvents = true
+
+	session := createSessionFromCluster(cluster, t)
 	defer session.Close()
-	session.stmtsLRU.max(4)
 
 	if err := createTable(session, "CREATE TABLE gocql_test.prepcachetest (id int,mod int,PRIMARY KEY (id))"); err != nil {
 		t.Fatalf("failed to create table with error '%v'", err)

+ 17 - 2
conn_test.go

@@ -411,7 +411,7 @@ func TestStream0(t *testing.T) {
 	defer srv.Stop()
 
 	errorHandler := connErrorHandlerFn(func(conn *Conn, err error, closed bool) {
-		if !strings.HasPrefix(err.Error(), expErr) {
+		if !srv.isClosed() && !strings.HasPrefix(err.Error(), expErr) {
 			t.Errorf("expected to get error prefix %q got %q", expErr, err.Error())
 		}
 	})
@@ -521,7 +521,9 @@ type TestServer struct {
 	protocol   byte
 	headerSize int
 
-	quit chan struct{}
+	quit   chan struct{}
+	mu     sync.Mutex
+	closed bool
 }
 
 func (srv *TestServer) serve() {
@@ -552,7 +554,20 @@ func (srv *TestServer) serve() {
 	}
 }
 
+func (srv *TestServer) isClosed() bool {
+	srv.mu.Lock()
+	defer srv.mu.Unlock()
+	return srv.closed
+}
+
 func (srv *TestServer) Stop() {
+	srv.mu.Lock()
+	defer srv.mu.Unlock()
+	if srv.closed {
+		return
+	}
+	srv.closed = true
+
 	srv.listen.Close()
 	close(srv.quit)
 }