@@ -10,15 +10,17 @@ import (
10
10
"reflect"
11
11
"strconv"
12
12
"strings"
13
+ "sync/atomic"
13
14
"testing"
14
15
"time"
15
16
16
- "github.com/go-mysql-org/go-mysql/client"
17
- "github.com/go-mysql-org/go-mysql/mysql"
18
- "github.com/go-mysql-org/go-mysql/server"
19
17
"github.com/pingcap/errors"
20
18
"github.com/siddontang/go/log"
21
19
"github.com/stretchr/testify/require"
20
+
21
+ "github.com/go-mysql-org/go-mysql/client"
22
+ "github.com/go-mysql-org/go-mysql/mysql"
23
+ "github.com/go-mysql-org/go-mysql/server"
22
24
)
23
25
24
26
var _ server.Handler = & mockHandler {}
@@ -32,7 +34,7 @@ type testServer struct {
32
34
33
35
type mockHandler struct {
34
36
// the number of times a query executed
35
- queryCount int
37
+ queryCount atomic. Int32
36
38
}
37
39
38
40
func TestDriverOptions_SetRetriesOn (t * testing.T ) {
@@ -54,7 +56,7 @@ func TestDriverOptions_SetRetriesOn(t *testing.T) {
54
56
55
57
// here we issue assert that even though we only issued 1 query, that the retries
56
58
// remained on and there were 3 calls to the DB.
57
- require .Equal (t , 3 , srv .handler .queryCount )
59
+ require .EqualValues (t , 3 , srv .handler .queryCount . Load () )
58
60
}
59
61
60
62
func TestDriverOptions_SetRetriesOff (t * testing.T ) {
@@ -75,7 +77,7 @@ func TestDriverOptions_SetRetriesOff(t *testing.T) {
75
77
76
78
// here we issue assert that even though we only issued 1 query, that the retries
77
79
// remained on and there were 3 calls to the DB.
78
- require .Equal (t , 1 , srv .handler .queryCount )
80
+ require .EqualValues (t , 1 , srv .handler .queryCount . Load () )
79
81
}
80
82
81
83
func TestDriverOptions_SetCollation (t * testing.T ) {
@@ -309,7 +311,7 @@ func (h *mockHandler) UseDB(dbName string) error {
309
311
}
310
312
311
313
func (h * mockHandler ) handleQuery (query string , binary bool , args []interface {}) (* mysql.Result , error ) {
312
- h .queryCount ++
314
+ h .queryCount . Add ( 1 )
313
315
ss := strings .Split (query , " " )
314
316
switch strings .ToLower (ss [0 ]) {
315
317
case "select" :
0 commit comments