Prechádzať zdrojové kódy

optional concurrent test

Julien Schmidt 12 rokov pred
rodič
commit
c0c3041b4e
1 zmenil súbory, kde vykonal 41 pridanie a 0 odobranie
  1. 41 0
      driver_test.go

+ 41 - 0
driver_test.go

@@ -7,6 +7,7 @@ import (
 	"os"
 	"sync"
 	"testing"
+	"time"
 )
 
 var (
@@ -630,3 +631,43 @@ func TestStmtMultiRows(t *testing.T) {
 	}
 
 }
+
+var canStop bool
+
+func doStuff(t *testing.T) {
+	db, err := sql.Open("mysql", dsn)
+	if err != nil {
+		t.Fatalf("Error connecting: %v", err)
+	}
+
+	defer db.Close()
+
+	for !canStop {
+		_, err := db.Exec("SELECT 1")
+		if err != nil {
+			canStop = true
+			t.Fatalf(err.Error())
+		}
+	}
+}
+
+func TestConcurrent(t *testing.T) {
+	if os.Getenv("MYSQL_TEST_CONCURRENT") != "1" {
+		t.Log("CONCURRENT env var not set. Skipping TestConcurrent")
+		return
+	}
+	if !getEnv() {
+		t.Logf("MySQL-Server not running on %s. Skipping TestConcurrent", netAddr)
+		return
+	}
+
+	fmt.Println("Run")
+
+	canStop = false
+	for i := 0; i < 500; i++ {
+		go doStuff(t)
+	}
+
+	time.Sleep(3 * time.Second)
+	canStop = true
+}