Bläddra i källkod

added impl.close() to make sure the connections stop retrying after returning error to user. Added test case to make sure CreateSession does not block indefinitely again.

Phillip Couto 12 år sedan
förälder
incheckning
e01e597535
2 ändrade filer med 16 tillägg och 0 borttagningar
  1. 15 0
      cassandra_test.go
  2. 1 0
      cluster.go

+ 15 - 0
cassandra_test.go

@@ -272,6 +272,21 @@ func TestBatchLimit(t *testing.T) {
 
 
 }
 }
 
 
+// TestCreateSessionTimeout tests to make sure the CreateSession function timeouts out correctly
+// and prevents an infinite loop of connection retries.
+func TestCreateSessionTimeout(t *testing.T) {
+	go func() {
+		<-time.After(2 * time.Second)
+		t.Fatal("no startup timeout")
+	}()
+	c := NewCluster("127.0.0.1:1")
+	c.StartupTimeout = 1 * time.Second
+
+	if _, err := c.CreateSession(); err != ErrNoConnections {
+		t.Fatal("Create session did not fail with the ErrNoConnections error.")
+	}
+}
+
 type Page struct {
 type Page struct {
 	Title       string
 	Title       string
 	RevId       UUID
 	RevId       UUID

+ 1 - 0
cluster.go

@@ -89,6 +89,7 @@ func (cfg *ClusterConfig) CreateSession() (*Session, error) {
 		s.SetConsistency(cfg.Consistency)
 		s.SetConsistency(cfg.Consistency)
 		return s, nil
 		return s, nil
 	case <-time.After(cfg.StartupTimeout):
 	case <-time.After(cfg.StartupTimeout):
+		impl.Close()
 		return nil, ErrNoConnections
 		return nil, ErrNoConnections
 	}
 	}