Skip to content

Commit c0c3041

Browse files
committed
optional concurrent test
1 parent d1deaee commit c0c3041

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

driver_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"sync"
99
"testing"
10+
"time"
1011
)
1112

1213
var (
@@ -630,3 +631,43 @@ func TestStmtMultiRows(t *testing.T) {
630631
}
631632

632633
}
634+
635+
var canStop bool
636+
637+
func doStuff(t *testing.T) {
638+
db, err := sql.Open("mysql", dsn)
639+
if err != nil {
640+
t.Fatalf("Error connecting: %v", err)
641+
}
642+
643+
defer db.Close()
644+
645+
for !canStop {
646+
_, err := db.Exec("SELECT 1")
647+
if err != nil {
648+
canStop = true
649+
t.Fatalf(err.Error())
650+
}
651+
}
652+
}
653+
654+
func TestConcurrent(t *testing.T) {
655+
if os.Getenv("MYSQL_TEST_CONCURRENT") != "1" {
656+
t.Log("CONCURRENT env var not set. Skipping TestConcurrent")
657+
return
658+
}
659+
if !getEnv() {
660+
t.Logf("MySQL-Server not running on %s. Skipping TestConcurrent", netAddr)
661+
return
662+
}
663+
664+
fmt.Println("Run")
665+
666+
canStop = false
667+
for i := 0; i < 500; i++ {
668+
go doStuff(t)
669+
}
670+
671+
time.Sleep(3 * time.Second)
672+
canStop = true
673+
}

0 commit comments

Comments
 (0)