Ver código fonte

add test to verify #439

Chris Bannister 10 anos atrás
pai
commit
348a026a96
1 arquivos alterados com 47 adições e 0 exclusões
  1. 47 0
      conn_test.go

+ 47 - 0
conn_test.go

@@ -569,6 +569,53 @@ func TestQueryTimeoutClose(t *testing.T) {
 	}
 }
 
+func TestExecPanic(t *testing.T) {
+	srv := NewTestServer(t, defaultProto)
+	defer srv.Stop()
+
+	cluster := NewCluster(srv.Address)
+	// Set the timeout arbitrarily low so that the query hits the timeout in a
+	// timely manner.
+	cluster.Timeout = 5 * time.Millisecond
+	cluster.NumConns = 1
+	// cluster.NumStreams = 1
+
+	db, err := cluster.CreateSession()
+	if err != nil {
+		t.Fatal(err)
+	}
+	defer db.Close()
+
+	streams := db.cfg.NumStreams
+
+	wg := &sync.WaitGroup{}
+	wg.Add(streams)
+	for i := 0; i < streams; i++ {
+		go func() {
+			defer wg.Done()
+			q := db.Query("void")
+			for {
+				if err := q.Exec(); err != nil {
+					return
+				}
+			}
+		}()
+	}
+
+	wg.Add(1)
+
+	go func() {
+		defer wg.Done()
+		for i := 0; i < int(TimeoutLimit); i++ {
+			db.Query("timeout").Exec()
+		}
+	}()
+
+	wg.Wait()
+
+	time.Sleep(500 * time.Millisecond)
+}
+
 func NewTestServer(t testing.TB, protocol uint8) *TestServer {
 	laddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
 	if err != nil {