@@ -11,6 +11,7 @@ package mysql
11
11
import (
12
12
"bytes"
13
13
"context"
14
+ "crypto/rand"
14
15
"crypto/tls"
15
16
"database/sql"
16
17
"database/sql/driver"
@@ -149,8 +150,9 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
149
150
}
150
151
defer db .Close ()
151
152
152
- // Previous test may be skipped without dropping the test table
153
- db .Exec ("DROP TABLE IF EXISTS test" )
153
+ cleanup := func () {
154
+ db .Exec ("DROP TABLE IF EXISTS test" )
155
+ }
154
156
155
157
dsn2 := dsn + "&interpolateParams=true"
156
158
var db2 * sql.DB
@@ -163,21 +165,80 @@ func runTests(t *testing.T, dsn string, tests ...func(dbt *DBTest)) {
163
165
}
164
166
165
167
for _ , test := range tests {
168
+ test := test
166
169
t .Run ("default" , func (t * testing.T ) {
167
170
dbt := & DBTest {t , db }
168
- defer dbt . db . Exec ( "DROP TABLE IF EXISTS test" )
171
+ t . Cleanup ( cleanup )
169
172
test (dbt )
170
173
})
171
174
if db2 != nil {
172
175
t .Run ("interpolateParams" , func (t * testing.T ) {
173
176
dbt2 := & DBTest {t , db2 }
174
- defer dbt2 . db . Exec ( "DROP TABLE IF EXISTS test" )
177
+ t . Cleanup ( cleanup )
175
178
test (dbt2 )
176
179
})
177
180
}
178
181
}
179
182
}
180
183
184
+ // runTestsParallel runs the tests in parallel with a separate database connection for each test.
185
+ func runTestsParallel (t * testing.T , dsn string , tests ... func (dbt * DBTest , tableName string )) {
186
+ if ! available {
187
+ t .Skipf ("MySQL server not running on %s" , netAddr )
188
+ }
189
+
190
+ newTableName := func (t * testing.T ) string {
191
+ t .Helper ()
192
+ var buf [8 ]byte
193
+ if _ , err := rand .Read (buf [:]); err != nil {
194
+ t .Fatal (err )
195
+ }
196
+ return fmt .Sprintf ("test_%x" , buf [:])
197
+ }
198
+
199
+ t .Parallel ()
200
+ for _ , test := range tests {
201
+ test := test
202
+
203
+ t .Run ("default" , func (t * testing.T ) {
204
+ t .Parallel ()
205
+
206
+ tableName := newTableName (t )
207
+ db , err := sql .Open ("mysql" , dsn )
208
+ if err != nil {
209
+ t .Fatalf ("error connecting: %s" , err .Error ())
210
+ }
211
+ t .Cleanup (func () {
212
+ db .Exec ("DROP TABLE IF EXISTS " + tableName )
213
+ db .Close ()
214
+ })
215
+
216
+ dbt := & DBTest {t , db }
217
+ test (dbt , tableName )
218
+ })
219
+
220
+ dsn2 := dsn + "&interpolateParams=true"
221
+ if _ , err := ParseDSN (dsn2 ); err == errInvalidDSNUnsafeCollation {
222
+ t .Run ("interpolateParams" , func (t * testing.T ) {
223
+ t .Parallel ()
224
+
225
+ tableName := newTableName (t )
226
+ db , err := sql .Open ("mysql" , dsn2 )
227
+ if err != nil {
228
+ t .Fatalf ("error connecting: %s" , err .Error ())
229
+ }
230
+ t .Cleanup (func () {
231
+ db .Exec ("DROP TABLE IF EXISTS " + tableName )
232
+ db .Close ()
233
+ })
234
+
235
+ dbt := & DBTest {t , db }
236
+ test (dbt , tableName )
237
+ })
238
+ }
239
+ }
240
+ }
241
+
181
242
func (dbt * DBTest ) fail (method , query string , err error ) {
182
243
dbt .Helper ()
183
244
if len (query ) > 300 {
@@ -216,7 +277,7 @@ func maybeSkip(t *testing.T, err error, skipErrno uint16) {
216
277
}
217
278
218
279
func TestEmptyQuery (t * testing.T ) {
219
- runTests (t , dsn , func (dbt * DBTest ) {
280
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
220
281
// just a comment, no query
221
282
rows := dbt .mustQuery ("--" )
222
283
defer rows .Close ()
@@ -228,20 +289,20 @@ func TestEmptyQuery(t *testing.T) {
228
289
}
229
290
230
291
func TestCRUD (t * testing.T ) {
231
- runTests (t , dsn , func (dbt * DBTest ) {
292
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
232
293
// Create Table
233
- dbt .mustExec ("CREATE TABLE test (value BOOL)" )
294
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value BOOL)" )
234
295
235
296
// Test for unexpected data
236
297
var out bool
237
- rows := dbt .mustQuery ("SELECT * FROM test" )
298
+ rows := dbt .mustQuery ("SELECT * FROM " + tbl )
238
299
if rows .Next () {
239
300
dbt .Error ("unexpected data in empty table" )
240
301
}
241
302
rows .Close ()
242
303
243
304
// Create Data
244
- res := dbt .mustExec ("INSERT INTO test VALUES (1)" )
305
+ res := dbt .mustExec ("INSERT INTO " + tbl + " VALUES (1)" )
245
306
count , err := res .RowsAffected ()
246
307
if err != nil {
247
308
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -259,7 +320,7 @@ func TestCRUD(t *testing.T) {
259
320
}
260
321
261
322
// Read
262
- rows = dbt .mustQuery ("SELECT value FROM test" )
323
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
263
324
if rows .Next () {
264
325
rows .Scan (& out )
265
326
if true != out {
@@ -275,7 +336,7 @@ func TestCRUD(t *testing.T) {
275
336
rows .Close ()
276
337
277
338
// Update
278
- res = dbt .mustExec ("UPDATE test SET value = ? WHERE value = ?" , false , true )
339
+ res = dbt .mustExec ("UPDATE " + tbl + " SET value = ? WHERE value = ?" , false , true )
279
340
count , err = res .RowsAffected ()
280
341
if err != nil {
281
342
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -285,7 +346,7 @@ func TestCRUD(t *testing.T) {
285
346
}
286
347
287
348
// Check Update
288
- rows = dbt .mustQuery ("SELECT value FROM test" )
349
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
289
350
if rows .Next () {
290
351
rows .Scan (& out )
291
352
if false != out {
@@ -301,7 +362,7 @@ func TestCRUD(t *testing.T) {
301
362
rows .Close ()
302
363
303
364
// Delete
304
- res = dbt .mustExec ("DELETE FROM test WHERE value = ?" , false )
365
+ res = dbt .mustExec ("DELETE FROM " + tbl + " WHERE value = ?" , false )
305
366
count , err = res .RowsAffected ()
306
367
if err != nil {
307
368
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -311,7 +372,7 @@ func TestCRUD(t *testing.T) {
311
372
}
312
373
313
374
// Check for unexpected rows
314
- res = dbt .mustExec ("DELETE FROM test" )
375
+ res = dbt .mustExec ("DELETE FROM " + tbl )
315
376
count , err = res .RowsAffected ()
316
377
if err != nil {
317
378
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -325,13 +386,13 @@ func TestCRUD(t *testing.T) {
325
386
// TestNumbers test that selecting numeric columns.
326
387
// Both of textRows and binaryRows should return same type and value.
327
388
func TestNumbersToAny (t * testing.T ) {
328
- runTests (t , dsn , func (dbt * DBTest ) {
329
- dbt .mustExec ("CREATE TABLE `test` (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " +
389
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
390
+ dbt .mustExec ("CREATE TABLE " + tbl + " (id INT PRIMARY KEY, b BOOL, i8 TINYINT, " +
330
391
"i16 SMALLINT, i32 INT, i64 BIGINT, f32 FLOAT, f64 DOUBLE)" )
331
- dbt .mustExec ("INSERT INTO `test` VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)" )
392
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (1, true, 127, 32767, 2147483647, 9223372036854775807, 1.25, 2.5)" )
332
393
333
394
// Use binaryRows for intarpolateParams=false and textRows for intarpolateParams=true.
334
- rows := dbt .mustQuery ("SELECT b, i8, i16, i32, i64, f32, f64 FROM `test` WHERE id=?" , 1 )
395
+ rows := dbt .mustQuery ("SELECT b, i8, i16, i32, i64, f32, f64 FROM " + tbl + " WHERE id=?" , 1 )
335
396
if ! rows .Next () {
336
397
dbt .Fatal ("no data" )
337
398
}
@@ -410,19 +471,19 @@ func TestMultiQuery(t *testing.T) {
410
471
}
411
472
412
473
func TestInt (t * testing.T ) {
413
- runTests (t , dsn , func (dbt * DBTest ) {
474
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
414
475
types := [5 ]string {"TINYINT" , "SMALLINT" , "MEDIUMINT" , "INT" , "BIGINT" }
415
476
in := int64 (42 )
416
477
var out int64
417
478
var rows * sql.Rows
418
479
419
480
// SIGNED
420
481
for _ , v := range types {
421
- dbt .mustExec ("CREATE TABLE test (value " + v + ")" )
482
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value " + v + ")" )
422
483
423
- dbt .mustExec ("INSERT INTO test VALUES (?)" , in )
484
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
424
485
425
- rows = dbt .mustQuery ("SELECT value FROM test" )
486
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
426
487
if rows .Next () {
427
488
rows .Scan (& out )
428
489
if in != out {
@@ -433,16 +494,16 @@ func TestInt(t *testing.T) {
433
494
}
434
495
rows .Close ()
435
496
436
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
497
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
437
498
}
438
499
439
500
// UNSIGNED ZEROFILL
440
501
for _ , v := range types {
441
- dbt .mustExec ("CREATE TABLE test (value " + v + " ZEROFILL)" )
502
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value " + v + " ZEROFILL)" )
442
503
443
- dbt .mustExec ("INSERT INTO test VALUES (?)" , in )
504
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
444
505
445
- rows = dbt .mustQuery ("SELECT value FROM test" )
506
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
446
507
if rows .Next () {
447
508
rows .Scan (& out )
448
509
if in != out {
@@ -453,21 +514,21 @@ func TestInt(t *testing.T) {
453
514
}
454
515
rows .Close ()
455
516
456
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
517
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
457
518
}
458
519
})
459
520
}
460
521
461
522
func TestFloat32 (t * testing.T ) {
462
- runTests (t , dsn , func (dbt * DBTest ) {
523
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
463
524
types := [2 ]string {"FLOAT" , "DOUBLE" }
464
525
in := float32 (42.23 )
465
526
var out float32
466
527
var rows * sql.Rows
467
528
for _ , v := range types {
468
- dbt .mustExec ("CREATE TABLE test (value " + v + ")" )
469
- dbt .mustExec ("INSERT INTO test VALUES (?)" , in )
470
- rows = dbt .mustQuery ("SELECT value FROM test" )
529
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value " + v + ")" )
530
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
531
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
471
532
if rows .Next () {
472
533
rows .Scan (& out )
473
534
if in != out {
@@ -477,21 +538,21 @@ func TestFloat32(t *testing.T) {
477
538
dbt .Errorf ("%s: no data" , v )
478
539
}
479
540
rows .Close ()
480
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
541
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
481
542
}
482
543
})
483
544
}
484
545
485
546
func TestFloat64 (t * testing.T ) {
486
- runTests (t , dsn , func (dbt * DBTest ) {
547
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
487
548
types := [2 ]string {"FLOAT" , "DOUBLE" }
488
549
var expected float64 = 42.23
489
550
var out float64
490
551
var rows * sql.Rows
491
552
for _ , v := range types {
492
- dbt .mustExec ("CREATE TABLE test (value " + v + ")" )
493
- dbt .mustExec ("INSERT INTO test VALUES (42.23)" )
494
- rows = dbt .mustQuery ("SELECT value FROM test" )
553
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value " + v + ")" )
554
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (42.23)" )
555
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
495
556
if rows .Next () {
496
557
rows .Scan (& out )
497
558
if expected != out {
@@ -501,21 +562,21 @@ func TestFloat64(t *testing.T) {
501
562
dbt .Errorf ("%s: no data" , v )
502
563
}
503
564
rows .Close ()
504
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
565
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
505
566
}
506
567
})
507
568
}
508
569
509
570
func TestFloat64Placeholder (t * testing.T ) {
510
- runTests (t , dsn , func (dbt * DBTest ) {
571
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
511
572
types := [2 ]string {"FLOAT" , "DOUBLE" }
512
573
var expected float64 = 42.23
513
574
var out float64
514
575
var rows * sql.Rows
515
576
for _ , v := range types {
516
- dbt .mustExec ("CREATE TABLE test (id int, value " + v + ")" )
517
- dbt .mustExec ("INSERT INTO test VALUES (1, 42.23)" )
518
- rows = dbt .mustQuery ("SELECT value FROM test WHERE id = ?" , 1 )
577
+ dbt .mustExec ("CREATE TABLE " + tbl + " (id int, value " + v + ")" )
578
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (1, 42.23)" )
579
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl + " WHERE id = ?" , 1 )
519
580
if rows .Next () {
520
581
rows .Scan (& out )
521
582
if expected != out {
@@ -525,24 +586,24 @@ func TestFloat64Placeholder(t *testing.T) {
525
586
dbt .Errorf ("%s: no data" , v )
526
587
}
527
588
rows .Close ()
528
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
589
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
529
590
}
530
591
})
531
592
}
532
593
533
594
func TestString (t * testing.T ) {
534
- runTests (t , dsn , func (dbt * DBTest ) {
595
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
535
596
types := [6 ]string {"CHAR(255)" , "VARCHAR(255)" , "TINYTEXT" , "TEXT" , "MEDIUMTEXT" , "LONGTEXT" }
536
597
in := "κόσμε üöäßñóùéàâÿœ'îë Árvíztűrő いろはにほへとちりぬるを イロハニホヘト דג סקרן чащах น่าฟังเอย"
537
598
var out string
538
599
var rows * sql.Rows
539
600
540
601
for _ , v := range types {
541
- dbt .mustExec ("CREATE TABLE test (value " + v + ") CHARACTER SET utf8" )
602
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value " + v + ") CHARACTER SET utf8" )
542
603
543
- dbt .mustExec ("INSERT INTO test VALUES (?)" , in )
604
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
544
605
545
- rows = dbt .mustQuery ("SELECT value FROM test" )
606
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
546
607
if rows .Next () {
547
608
rows .Scan (& out )
548
609
if in != out {
@@ -553,11 +614,11 @@ func TestString(t *testing.T) {
553
614
}
554
615
rows .Close ()
555
616
556
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
617
+ dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
557
618
}
558
619
559
620
// BLOB
560
- dbt .mustExec ("CREATE TABLE test (id int, value BLOB) CHARACTER SET utf8" )
621
+ dbt .mustExec ("CREATE TABLE " + tbl + " (id int, value BLOB) CHARACTER SET utf8" )
561
622
562
623
id := 2
563
624
in = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, " +
@@ -568,9 +629,9 @@ func TestString(t *testing.T) {
568
629
"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, " +
569
630
"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. " +
570
631
"Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
571
- dbt .mustExec ("INSERT INTO test VALUES (?, ?)" , id , in )
632
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?, ?)" , id , in )
572
633
573
- err := dbt .db .QueryRow ("SELECT value FROM test WHERE id = ?" , id ).Scan (& out )
634
+ err := dbt .db .QueryRow ("SELECT value FROM " + tbl + " WHERE id = ?" , id ).Scan (& out )
574
635
if err != nil {
575
636
dbt .Fatalf ("Error on BLOB-Query: %s" , err .Error ())
576
637
} else if out != in {
@@ -580,7 +641,7 @@ func TestString(t *testing.T) {
580
641
}
581
642
582
643
func TestRawBytes (t * testing.T ) {
583
- runTests (t , dsn , func (dbt * DBTest ) {
644
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
584
645
v1 := []byte ("aaa" )
585
646
v2 := []byte ("bbb" )
586
647
rows := dbt .mustQuery ("SELECT ?, ?" , v1 , v2 )
@@ -609,7 +670,7 @@ func TestRawBytes(t *testing.T) {
609
670
}
610
671
611
672
func TestRawMessage (t * testing.T ) {
612
- runTests (t , dsn , func (dbt * DBTest ) {
673
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
613
674
v1 := json .RawMessage ("{}" )
614
675
v2 := json .RawMessage ("[]" )
615
676
rows := dbt .mustQuery ("SELECT ?, ?" , v1 , v2 )
@@ -640,14 +701,14 @@ func (tv testValuer) Value() (driver.Value, error) {
640
701
}
641
702
642
703
func TestValuer (t * testing.T ) {
643
- runTests (t , dsn , func (dbt * DBTest ) {
704
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
644
705
in := testValuer {"a_value" }
645
706
var out string
646
707
var rows * sql.Rows
647
708
648
- dbt .mustExec ("CREATE TABLE test (value VARCHAR(255)) CHARACTER SET utf8" )
649
- dbt .mustExec ("INSERT INTO test VALUES (?)" , in )
650
- rows = dbt .mustQuery ("SELECT value FROM test" )
709
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value VARCHAR(255)) CHARACTER SET utf8" )
710
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
711
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
651
712
if rows .Next () {
652
713
rows .Scan (& out )
653
714
if in .value != out {
@@ -657,8 +718,6 @@ func TestValuer(t *testing.T) {
657
718
dbt .Errorf ("Valuer: no data" )
658
719
}
659
720
rows .Close ()
660
-
661
- dbt .mustExec ("DROP TABLE IF EXISTS test" )
662
721
})
663
722
}
664
723
@@ -675,15 +734,15 @@ func (tv testValuerWithValidation) Value() (driver.Value, error) {
675
734
}
676
735
677
736
func TestValuerWithValidation (t * testing.T ) {
678
- runTests (t , dsn , func (dbt * DBTest ) {
737
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
679
738
in := testValuerWithValidation {"a_value" }
680
739
var out string
681
740
var rows * sql.Rows
682
741
683
- dbt .mustExec ("CREATE TABLE testValuer (value VARCHAR(255)) CHARACTER SET utf8" )
684
- dbt .mustExec ("INSERT INTO testValuer VALUES (?)" , in )
742
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value VARCHAR(255)) CHARACTER SET utf8" )
743
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?)" , in )
685
744
686
- rows = dbt .mustQuery ("SELECT value FROM testValuer" )
745
+ rows = dbt .mustQuery ("SELECT value FROM " + tbl )
687
746
defer rows .Close ()
688
747
689
748
if rows .Next () {
@@ -695,19 +754,17 @@ func TestValuerWithValidation(t *testing.T) {
695
754
dbt .Errorf ("Valuer: no data" )
696
755
}
697
756
698
- if _ , err := dbt .db .Exec ("INSERT INTO testValuer VALUES (?)" , testValuerWithValidation {"" }); err == nil {
757
+ if _ , err := dbt .db .Exec ("INSERT INTO " + tbl + " VALUES (?)" , testValuerWithValidation {"" }); err == nil {
699
758
dbt .Errorf ("Failed to check valuer error" )
700
759
}
701
760
702
- if _ , err := dbt .db .Exec ("INSERT INTO testValuer VALUES (?)" , nil ); err != nil {
761
+ if _ , err := dbt .db .Exec ("INSERT INTO " + tbl + " VALUES (?)" , nil ); err != nil {
703
762
dbt .Errorf ("Failed to check nil" )
704
763
}
705
764
706
- if _ , err := dbt .db .Exec ("INSERT INTO testValuer VALUES (?)" , map [string ]bool {}); err == nil {
765
+ if _ , err := dbt .db .Exec ("INSERT INTO " + tbl + " VALUES (?)" , map [string ]bool {}); err == nil {
707
766
dbt .Errorf ("Failed to check not valuer" )
708
767
}
709
-
710
- dbt .mustExec ("DROP TABLE IF EXISTS testValuer" )
711
768
})
712
769
}
713
770
@@ -941,7 +998,7 @@ func TestTimestampMicros(t *testing.T) {
941
998
f0 := format [:19 ]
942
999
f1 := format [:21 ]
943
1000
f6 := format [:26 ]
944
- runTests (t , dsn , func (dbt * DBTest ) {
1001
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
945
1002
// check if microseconds are supported.
946
1003
// Do not use timestamp(x) for that check - before 5.5.6, x would mean display width
947
1004
// and not precision.
@@ -956,7 +1013,7 @@ func TestTimestampMicros(t *testing.T) {
956
1013
return
957
1014
}
958
1015
_ , err := dbt .db .Exec (`
959
- CREATE TABLE test (
1016
+ CREATE TABLE ` + tbl + ` (
960
1017
value0 TIMESTAMP NOT NULL DEFAULT '` + f0 + `',
961
1018
value1 TIMESTAMP(1) NOT NULL DEFAULT '` + f1 + `',
962
1019
value6 TIMESTAMP(6) NOT NULL DEFAULT '` + f6 + `'
@@ -965,10 +1022,10 @@ func TestTimestampMicros(t *testing.T) {
965
1022
if err != nil {
966
1023
dbt .Error (err )
967
1024
}
968
- defer dbt .mustExec ("DROP TABLE IF EXISTS test" )
969
- dbt .mustExec ("INSERT INTO test SET value0=?, value1=?, value6=?" , f0 , f1 , f6 )
1025
+ defer dbt .mustExec ("DROP TABLE IF EXISTS " + tbl )
1026
+ dbt .mustExec ("INSERT INTO " + tbl + " SET value0=?, value1=?, value6=?" , f0 , f1 , f6 )
970
1027
var res0 , res1 , res6 string
971
- rows := dbt .mustQuery ("SELECT * FROM test" )
1028
+ rows := dbt .mustQuery ("SELECT * FROM " + tbl )
972
1029
defer rows .Close ()
973
1030
if ! rows .Next () {
974
1031
dbt .Errorf ("test contained no selectable values" )
@@ -990,7 +1047,7 @@ func TestTimestampMicros(t *testing.T) {
990
1047
}
991
1048
992
1049
func TestNULL (t * testing.T ) {
993
- runTests (t , dsn , func (dbt * DBTest ) {
1050
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
994
1051
nullStmt , err := dbt .db .Prepare ("SELECT NULL" )
995
1052
if err != nil {
996
1053
dbt .Fatal (err )
@@ -1122,12 +1179,12 @@ func TestNULL(t *testing.T) {
1122
1179
}
1123
1180
1124
1181
// Insert NULL
1125
- dbt .mustExec ("CREATE TABLE test (dummmy1 int, value int, dummy2 int)" )
1182
+ dbt .mustExec ("CREATE TABLE " + tbl + " (dummmy1 int, value int, dummy2 int)" )
1126
1183
1127
- dbt .mustExec ("INSERT INTO test VALUES (?, ?, ?)" , 1 , nil , 2 )
1184
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (?, ?, ?)" , 1 , nil , 2 )
1128
1185
1129
1186
var out interface {}
1130
- rows := dbt .mustQuery ("SELECT * FROM test" )
1187
+ rows := dbt .mustQuery ("SELECT * FROM " + tbl )
1131
1188
defer rows .Close ()
1132
1189
if rows .Next () {
1133
1190
rows .Scan (& out )
@@ -1151,7 +1208,7 @@ func TestUint64(t *testing.T) {
1151
1208
shigh = int64 (uhigh )
1152
1209
stop = ^ shigh
1153
1210
)
1154
- runTests (t , dsn , func (dbt * DBTest ) {
1211
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
1155
1212
stmt , err := dbt .db .Prepare (`SELECT ?, ?, ? ,?, ?, ?, ?, ?` )
1156
1213
if err != nil {
1157
1214
dbt .Fatal (err )
@@ -1347,20 +1404,20 @@ func TestLoadData(t *testing.T) {
1347
1404
})
1348
1405
}
1349
1406
1350
- func TestFoundRows (t * testing.T ) {
1351
- runTests (t , dsn , func (dbt * DBTest ) {
1352
- dbt .mustExec ("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)" )
1353
- dbt .mustExec ("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1407
+ func TestFoundRows1 (t * testing.T ) {
1408
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
1409
+ dbt .mustExec ("CREATE TABLE " + tbl + " (id INT NOT NULL ,data INT NOT NULL)" )
1410
+ dbt .mustExec ("INSERT INTO " + tbl + " (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1354
1411
1355
- res := dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 0" )
1412
+ res := dbt .mustExec ("UPDATE " + tbl + " SET data = 1 WHERE id = 0" )
1356
1413
count , err := res .RowsAffected ()
1357
1414
if err != nil {
1358
1415
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
1359
1416
}
1360
1417
if count != 2 {
1361
1418
dbt .Fatalf ("Expected 2 affected rows, got %d" , count )
1362
1419
}
1363
- res = dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 1" )
1420
+ res = dbt .mustExec ("UPDATE " + tbl + " SET data = 1 WHERE id = 1" )
1364
1421
count , err = res .RowsAffected ()
1365
1422
if err != nil {
1366
1423
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -1369,19 +1426,22 @@ func TestFoundRows(t *testing.T) {
1369
1426
dbt .Fatalf ("Expected 2 affected rows, got %d" , count )
1370
1427
}
1371
1428
})
1372
- runTests (t , dsn + "&clientFoundRows=true" , func (dbt * DBTest ) {
1373
- dbt .mustExec ("CREATE TABLE test (id INT NOT NULL ,data INT NOT NULL)" )
1374
- dbt .mustExec ("INSERT INTO test (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1429
+ }
1430
+
1431
+ func TestFoundRows2 (t * testing.T ) {
1432
+ runTestsParallel (t , dsn + "&clientFoundRows=true" , func (dbt * DBTest , tbl string ) {
1433
+ dbt .mustExec ("CREATE TABLE " + tbl + " (id INT NOT NULL ,data INT NOT NULL)" )
1434
+ dbt .mustExec ("INSERT INTO " + tbl + " (id, data) VALUES (0, 0),(0, 0),(1, 0),(1, 0),(1, 1)" )
1375
1435
1376
- res := dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 0" )
1436
+ res := dbt .mustExec ("UPDATE " + tbl + " SET data = 1 WHERE id = 0" )
1377
1437
count , err := res .RowsAffected ()
1378
1438
if err != nil {
1379
1439
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
1380
1440
}
1381
1441
if count != 2 {
1382
1442
dbt .Fatalf ("Expected 2 matched rows, got %d" , count )
1383
1443
}
1384
- res = dbt .mustExec ("UPDATE test SET data = 1 WHERE id = 1" )
1444
+ res = dbt .mustExec ("UPDATE " + tbl + " SET data = 1 WHERE id = 1" )
1385
1445
count , err = res .RowsAffected ()
1386
1446
if err != nil {
1387
1447
dbt .Fatalf ("res.RowsAffected() returned error: %s" , err .Error ())
@@ -1507,7 +1567,7 @@ func TestCharset(t *testing.T) {
1507
1567
}
1508
1568
1509
1569
func TestFailingCharset (t * testing.T ) {
1510
- runTests (t , dsn + "&charset=none" , func (dbt * DBTest ) {
1570
+ runTestsParallel (t , dsn + "&charset=none" , func (dbt * DBTest , _ string ) {
1511
1571
// run query to really establish connection...
1512
1572
_ , err := dbt .db .Exec ("SELECT 1" )
1513
1573
if err == nil {
@@ -1556,7 +1616,7 @@ func TestCollation(t *testing.T) {
1556
1616
}
1557
1617
1558
1618
func TestColumnsWithAlias (t * testing.T ) {
1559
- runTests (t , dsn + "&columnsWithAlias=true" , func (dbt * DBTest ) {
1619
+ runTestsParallel (t , dsn + "&columnsWithAlias=true" , func (dbt * DBTest , _ string ) {
1560
1620
rows := dbt .mustQuery ("SELECT 1 AS A" )
1561
1621
defer rows .Close ()
1562
1622
cols , _ := rows .Columns ()
@@ -1580,7 +1640,7 @@ func TestColumnsWithAlias(t *testing.T) {
1580
1640
}
1581
1641
1582
1642
func TestRawBytesResultExceedsBuffer (t * testing.T ) {
1583
- runTests (t , dsn , func (dbt * DBTest ) {
1643
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
1584
1644
// defaultBufSize from buffer.go
1585
1645
expected := strings .Repeat ("abc" , defaultBufSize )
1586
1646
@@ -1639,7 +1699,7 @@ func TestTimezoneConversion(t *testing.T) {
1639
1699
// Special cases
1640
1700
1641
1701
func TestRowsClose (t * testing.T ) {
1642
- runTests (t , dsn , func (dbt * DBTest ) {
1702
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
1643
1703
rows , err := dbt .db .Query ("SELECT 1" )
1644
1704
if err != nil {
1645
1705
dbt .Fatal (err )
@@ -1664,7 +1724,7 @@ func TestRowsClose(t *testing.T) {
1664
1724
// dangling statements
1665
1725
// http://code.google.com/p/go/issues/detail?id=3865
1666
1726
func TestCloseStmtBeforeRows (t * testing.T ) {
1667
- runTests (t , dsn , func (dbt * DBTest ) {
1727
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
1668
1728
stmt , err := dbt .db .Prepare ("SELECT 1" )
1669
1729
if err != nil {
1670
1730
dbt .Fatal (err )
@@ -1705,7 +1765,7 @@ func TestCloseStmtBeforeRows(t *testing.T) {
1705
1765
// It is valid to have multiple Rows for the same Stmt
1706
1766
// http://code.google.com/p/go/issues/detail?id=3734
1707
1767
func TestStmtMultiRows (t * testing.T ) {
1708
- runTests (t , dsn , func (dbt * DBTest ) {
1768
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
1709
1769
stmt , err := dbt .db .Prepare ("SELECT 1 UNION SELECT 0" )
1710
1770
if err != nil {
1711
1771
dbt .Fatal (err )
@@ -2507,7 +2567,7 @@ func TestExecMultipleResults(t *testing.T) {
2507
2567
// tests if rows are set in a proper state if some results were ignored before
2508
2568
// calling rows.NextResultSet.
2509
2569
func TestSkipResults (t * testing.T ) {
2510
- runTests (t , dsn , func (dbt * DBTest ) {
2570
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
2511
2571
rows := dbt .mustQuery ("SELECT 1, 2" )
2512
2572
defer rows .Close ()
2513
2573
@@ -2562,7 +2622,7 @@ func TestQueryMultipleResults(t *testing.T) {
2562
2622
}
2563
2623
2564
2624
func TestPingContext (t * testing.T ) {
2565
- runTests (t , dsn , func (dbt * DBTest ) {
2625
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
2566
2626
ctx , cancel := context .WithCancel (context .Background ())
2567
2627
cancel ()
2568
2628
if err := dbt .db .PingContext (ctx ); err != context .Canceled {
@@ -2572,16 +2632,16 @@ func TestPingContext(t *testing.T) {
2572
2632
}
2573
2633
2574
2634
func TestContextCancelExec (t * testing.T ) {
2575
- runTests (t , dsn , func (dbt * DBTest ) {
2576
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2635
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2636
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2577
2637
ctx , cancel := context .WithCancel (context .Background ())
2578
2638
2579
2639
// Delay execution for just a bit until db.ExecContext has begun.
2580
2640
defer time .AfterFunc (250 * time .Millisecond , cancel ).Stop ()
2581
2641
2582
2642
// This query will be canceled.
2583
2643
startTime := time .Now ()
2584
- if _ , err := dbt .db .ExecContext (ctx , "INSERT INTO test VALUES (SLEEP(1))" ); err != context .Canceled {
2644
+ if _ , err := dbt .db .ExecContext (ctx , "INSERT INTO " + tbl + " VALUES (SLEEP(1))" ); err != context .Canceled {
2585
2645
dbt .Errorf ("expected context.Canceled, got %v" , err )
2586
2646
}
2587
2647
if d := time .Since (startTime ); d > 500 * time .Millisecond {
@@ -2593,22 +2653,22 @@ func TestContextCancelExec(t *testing.T) {
2593
2653
2594
2654
// Check how many times the query is executed.
2595
2655
var v int
2596
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2656
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2597
2657
dbt .Fatalf ("%s" , err .Error ())
2598
2658
}
2599
2659
if v != 1 { // TODO: need to kill the query, and v should be 0.
2600
2660
dbt .Skipf ("[WARN] expected val to be 1, got %d" , v )
2601
2661
}
2602
2662
2603
2663
// Context is already canceled, so error should come before execution.
2604
- if _ , err := dbt .db .ExecContext (ctx , "INSERT INTO test VALUES (1)" ); err == nil {
2664
+ if _ , err := dbt .db .ExecContext (ctx , "INSERT INTO " + tbl + " VALUES (1)" ); err == nil {
2605
2665
dbt .Error ("expected error" )
2606
2666
} else if err .Error () != "context canceled" {
2607
2667
dbt .Fatalf ("unexpected error: %s" , err )
2608
2668
}
2609
2669
2610
2670
// The second insert query will fail, so the table has no changes.
2611
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2671
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2612
2672
dbt .Fatalf ("%s" , err .Error ())
2613
2673
}
2614
2674
if v != 1 {
@@ -2618,16 +2678,16 @@ func TestContextCancelExec(t *testing.T) {
2618
2678
}
2619
2679
2620
2680
func TestContextCancelQuery (t * testing.T ) {
2621
- runTests (t , dsn , func (dbt * DBTest ) {
2622
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2681
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2682
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2623
2683
ctx , cancel := context .WithCancel (context .Background ())
2624
2684
2625
2685
// Delay execution for just a bit until db.ExecContext has begun.
2626
2686
defer time .AfterFunc (250 * time .Millisecond , cancel ).Stop ()
2627
2687
2628
2688
// This query will be canceled.
2629
2689
startTime := time .Now ()
2630
- if _ , err := dbt .db .QueryContext (ctx , "INSERT INTO test VALUES (SLEEP(1))" ); err != context .Canceled {
2690
+ if _ , err := dbt .db .QueryContext (ctx , "INSERT INTO " + tbl + " VALUES (SLEEP(1))" ); err != context .Canceled {
2631
2691
dbt .Errorf ("expected context.Canceled, got %v" , err )
2632
2692
}
2633
2693
if d := time .Since (startTime ); d > 500 * time .Millisecond {
@@ -2639,20 +2699,20 @@ func TestContextCancelQuery(t *testing.T) {
2639
2699
2640
2700
// Check how many times the query is executed.
2641
2701
var v int
2642
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2702
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2643
2703
dbt .Fatalf ("%s" , err .Error ())
2644
2704
}
2645
2705
if v != 1 { // TODO: need to kill the query, and v should be 0.
2646
2706
dbt .Skipf ("[WARN] expected val to be 1, got %d" , v )
2647
2707
}
2648
2708
2649
2709
// Context is already canceled, so error should come before execution.
2650
- if _ , err := dbt .db .QueryContext (ctx , "INSERT INTO test VALUES (1)" ); err != context .Canceled {
2710
+ if _ , err := dbt .db .QueryContext (ctx , "INSERT INTO " + tbl + " VALUES (1)" ); err != context .Canceled {
2651
2711
dbt .Errorf ("expected context.Canceled, got %v" , err )
2652
2712
}
2653
2713
2654
2714
// The second insert query will fail, so the table has no changes.
2655
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2715
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2656
2716
dbt .Fatalf ("%s" , err .Error ())
2657
2717
}
2658
2718
if v != 1 {
@@ -2662,12 +2722,12 @@ func TestContextCancelQuery(t *testing.T) {
2662
2722
}
2663
2723
2664
2724
func TestContextCancelQueryRow (t * testing.T ) {
2665
- runTests (t , dsn , func (dbt * DBTest ) {
2666
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2667
- dbt .mustExec ("INSERT INTO test VALUES (1), (2), (3)" )
2725
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2726
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2727
+ dbt .mustExec ("INSERT INTO " + tbl + " VALUES (1), (2), (3)" )
2668
2728
ctx , cancel := context .WithCancel (context .Background ())
2669
2729
2670
- rows , err := dbt .db .QueryContext (ctx , "SELECT v FROM test" )
2730
+ rows , err := dbt .db .QueryContext (ctx , "SELECT v FROM " + tbl )
2671
2731
if err != nil {
2672
2732
dbt .Fatalf ("%s" , err .Error ())
2673
2733
}
@@ -2695,7 +2755,7 @@ func TestContextCancelQueryRow(t *testing.T) {
2695
2755
}
2696
2756
2697
2757
func TestContextCancelPrepare (t * testing.T ) {
2698
- runTests (t , dsn , func (dbt * DBTest ) {
2758
+ runTestsParallel (t , dsn , func (dbt * DBTest , _ string ) {
2699
2759
ctx , cancel := context .WithCancel (context .Background ())
2700
2760
cancel ()
2701
2761
if _ , err := dbt .db .PrepareContext (ctx , "SELECT 1" ); err != context .Canceled {
@@ -2705,10 +2765,10 @@ func TestContextCancelPrepare(t *testing.T) {
2705
2765
}
2706
2766
2707
2767
func TestContextCancelStmtExec (t * testing.T ) {
2708
- runTests (t , dsn , func (dbt * DBTest ) {
2709
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2768
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2769
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2710
2770
ctx , cancel := context .WithCancel (context .Background ())
2711
- stmt , err := dbt .db .PrepareContext (ctx , "INSERT INTO test VALUES (SLEEP(1))" )
2771
+ stmt , err := dbt .db .PrepareContext (ctx , "INSERT INTO " + tbl + " VALUES (SLEEP(1))" )
2712
2772
if err != nil {
2713
2773
dbt .Fatalf ("unexpected error: %v" , err )
2714
2774
}
@@ -2730,7 +2790,7 @@ func TestContextCancelStmtExec(t *testing.T) {
2730
2790
2731
2791
// Check how many times the query is executed.
2732
2792
var v int
2733
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2793
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2734
2794
dbt .Fatalf ("%s" , err .Error ())
2735
2795
}
2736
2796
if v != 1 { // TODO: need to kill the query, and v should be 0.
@@ -2740,10 +2800,10 @@ func TestContextCancelStmtExec(t *testing.T) {
2740
2800
}
2741
2801
2742
2802
func TestContextCancelStmtQuery (t * testing.T ) {
2743
- runTests (t , dsn , func (dbt * DBTest ) {
2744
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2803
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2804
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2745
2805
ctx , cancel := context .WithCancel (context .Background ())
2746
- stmt , err := dbt .db .PrepareContext (ctx , "INSERT INTO test VALUES (SLEEP(1))" )
2806
+ stmt , err := dbt .db .PrepareContext (ctx , "INSERT INTO " + tbl + " VALUES (SLEEP(1))" )
2747
2807
if err != nil {
2748
2808
dbt .Fatalf ("unexpected error: %v" , err )
2749
2809
}
@@ -2765,7 +2825,7 @@ func TestContextCancelStmtQuery(t *testing.T) {
2765
2825
2766
2826
// Check how many times the query is executed.
2767
2827
var v int
2768
- if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM test" ).Scan (& v ); err != nil {
2828
+ if err := dbt .db .QueryRow ("SELECT COUNT(*) FROM " + tbl ).Scan (& v ); err != nil {
2769
2829
dbt .Fatalf ("%s" , err .Error ())
2770
2830
}
2771
2831
if v != 1 { // TODO: need to kill the query, and v should be 0.
@@ -2779,8 +2839,8 @@ func TestContextCancelBegin(t *testing.T) {
2779
2839
t .Skip (`FIXME: it sometime fails with "expected driver.ErrBadConn, got sql: connection is already closed" on windows and macOS` )
2780
2840
}
2781
2841
2782
- runTests (t , dsn , func (dbt * DBTest ) {
2783
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2842
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2843
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2784
2844
ctx , cancel := context .WithCancel (context .Background ())
2785
2845
conn , err := dbt .db .Conn (ctx )
2786
2846
if err != nil {
@@ -2797,7 +2857,7 @@ func TestContextCancelBegin(t *testing.T) {
2797
2857
2798
2858
// This query will be canceled.
2799
2859
startTime := time .Now ()
2800
- if _ , err := tx .ExecContext (ctx , "INSERT INTO test VALUES (SLEEP(1))" ); err != context .Canceled {
2860
+ if _ , err := tx .ExecContext (ctx , "INSERT INTO " + tbl + " VALUES (SLEEP(1))" ); err != context .Canceled {
2801
2861
dbt .Errorf ("expected context.Canceled, got %v" , err )
2802
2862
}
2803
2863
if d := time .Since (startTime ); d > 500 * time .Millisecond {
@@ -2835,8 +2895,8 @@ func TestContextCancelBegin(t *testing.T) {
2835
2895
}
2836
2896
2837
2897
func TestContextBeginIsolationLevel (t * testing.T ) {
2838
- runTests (t , dsn , func (dbt * DBTest ) {
2839
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2898
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2899
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2840
2900
ctx , cancel := context .WithCancel (context .Background ())
2841
2901
defer cancel ()
2842
2902
@@ -2854,13 +2914,13 @@ func TestContextBeginIsolationLevel(t *testing.T) {
2854
2914
dbt .Fatal (err )
2855
2915
}
2856
2916
2857
- _ , err = tx1 .ExecContext (ctx , "INSERT INTO test VALUES (1)" )
2917
+ _ , err = tx1 .ExecContext (ctx , "INSERT INTO " + tbl + " VALUES (1)" )
2858
2918
if err != nil {
2859
2919
dbt .Fatal (err )
2860
2920
}
2861
2921
2862
2922
var v int
2863
- row := tx2 .QueryRowContext (ctx , "SELECT COUNT(*) FROM test" )
2923
+ row := tx2 .QueryRowContext (ctx , "SELECT COUNT(*) FROM " + tbl )
2864
2924
if err := row .Scan (& v ); err != nil {
2865
2925
dbt .Fatal (err )
2866
2926
}
@@ -2874,7 +2934,7 @@ func TestContextBeginIsolationLevel(t *testing.T) {
2874
2934
dbt .Fatal (err )
2875
2935
}
2876
2936
2877
- row = tx2 .QueryRowContext (ctx , "SELECT COUNT(*) FROM test" )
2937
+ row = tx2 .QueryRowContext (ctx , "SELECT COUNT(*) FROM " + tbl )
2878
2938
if err := row .Scan (& v ); err != nil {
2879
2939
dbt .Fatal (err )
2880
2940
}
@@ -2887,8 +2947,8 @@ func TestContextBeginIsolationLevel(t *testing.T) {
2887
2947
}
2888
2948
2889
2949
func TestContextBeginReadOnly (t * testing.T ) {
2890
- runTests (t , dsn , func (dbt * DBTest ) {
2891
- dbt .mustExec ("CREATE TABLE test (v INTEGER)" )
2950
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
2951
+ dbt .mustExec ("CREATE TABLE " + tbl + " (v INTEGER)" )
2892
2952
ctx , cancel := context .WithCancel (context .Background ())
2893
2953
defer cancel ()
2894
2954
@@ -2903,14 +2963,14 @@ func TestContextBeginReadOnly(t *testing.T) {
2903
2963
}
2904
2964
2905
2965
// INSERT queries fail in a READ ONLY transaction.
2906
- _ , err = tx .ExecContext (ctx , "INSERT INTO test VALUES (1)" )
2966
+ _ , err = tx .ExecContext (ctx , "INSERT INTO " + tbl + " VALUES (1)" )
2907
2967
if _ , ok := err .(* MySQLError ); ! ok {
2908
2968
dbt .Errorf ("expected MySQLError, got %v" , err )
2909
2969
}
2910
2970
2911
2971
// SELECT queries can be executed.
2912
2972
var v int
2913
- row := tx .QueryRowContext (ctx , "SELECT COUNT(*) FROM test" )
2973
+ row := tx .QueryRowContext (ctx , "SELECT COUNT(*) FROM " + tbl )
2914
2974
if err := row .Scan (& v ); err != nil {
2915
2975
dbt .Fatal (err )
2916
2976
}
@@ -3147,9 +3207,9 @@ func TestRowsColumnTypes(t *testing.T) {
3147
3207
}
3148
3208
3149
3209
func TestValuerWithValueReceiverGivenNilValue (t * testing.T ) {
3150
- runTests (t , dsn , func (dbt * DBTest ) {
3151
- dbt .mustExec ("CREATE TABLE test (value VARCHAR(255))" )
3152
- dbt .db .Exec ("INSERT INTO test VALUES (?)" , (* testValuer )(nil ))
3210
+ runTestsParallel (t , dsn , func (dbt * DBTest , tbl string ) {
3211
+ dbt .mustExec ("CREATE TABLE " + tbl + " (value VARCHAR(255))" )
3212
+ dbt .db .Exec ("INSERT INTO " + tbl + " VALUES (?)" , (* testValuer )(nil ))
3153
3213
// This test will panic on the INSERT if ConvertValue() does not check for typed nil before calling Value()
3154
3214
})
3155
3215
}
0 commit comments