Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1bee809

Browse files
methanerusher
andauthored
test stability improvement. (#1699)
* ensuring performance schema is enabled when testing some performance schema results * do not use collations affected by MariaDB character_set_collations. * ensure using IANA timezone in test, since tzinfo depending on system won't have deprecated tz like "US/Central" and "US/Pacific" Co-authored-by: Diego Dupin <diego.dupin@mariadb.com>
1 parent 21ef4c6 commit 1bee809

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Daniel Montoya <dsmontoyam at gmail.com>
3737
Daniel Nichter <nil at codenode.com>
3838
Daniël van Eeden <git at myname.nl>
3939
Dave Protasowski <dprotaso at gmail.com>
40+
Diego Dupin <diego.dupin at gmail.com>
4041
Dirkjan Bussink <d.bussink at gmail.com>
4142
DisposaBoy <disposaboy at dby.me>
4243
Egor Smolyakov <egorsmkv at gmail.com>

‎driver_test.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,35 +1609,32 @@ func TestCollation(t *testing.T) {
16091609
t.Skipf("MySQL server not running on %s", netAddr)
16101610
}
16111611

1612-
defaultCollation := "utf8mb4_general_ci"
1612+
// MariaDB may override collation specified by handshake with `character_set_collations` variable.
1613+
// https://mariadb.com/kb/en/setting-character-sets-and-collations/#changing-default-collation
1614+
// https://mariadb.com/kb/en/server-system-variables/#character_set_collations
1615+
// utf8mb4_general_ci, utf8mb3_general_ci will be overridden by default MariaDB.
1616+
// Collations other than charasets default are not overridden. So utf8mb4_unicode_ci is safe.
16131617
testCollations := []string{
1614-
"", // do not set
1615-
defaultCollation, // driver default
16161618
"latin1_general_ci",
16171619
"binary",
16181620
"utf8mb4_unicode_ci",
16191621
"cp1257_bin",
16201622
}
16211623

16221624
for _, collation := range testCollations {
1623-
var expected, tdsn string
1624-
if collation != "" {
1625-
tdsn = dsn + "&collation=" + collation
1626-
expected = collation
1627-
} else {
1628-
tdsn = dsn
1629-
expected = defaultCollation
1630-
}
1631-
1632-
runTests(t, tdsn, func(dbt *DBTest) {
1633-
var got string
1634-
if err := dbt.db.QueryRow("SELECT @@collation_connection").Scan(&got); err != nil {
1635-
dbt.Fatal(err)
1636-
}
1625+
t.Run(collation, func(t *testing.T) {
1626+
tdsn := dsn + "&collation=" + collation
1627+
expected := collation
16371628

1638-
if got != expected {
1639-
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
1640-
}
1629+
runTests(t, tdsn, func(dbt *DBTest) {
1630+
var got string
1631+
if err := dbt.db.QueryRow("SELECT @@collation_connection").Scan(&got); err != nil {
1632+
dbt.Fatal(err)
1633+
}
1634+
if got != expected {
1635+
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
1636+
}
1637+
})
16411638
})
16421639
}
16431640
}
@@ -1685,16 +1682,16 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
16851682
}
16861683

16871684
func TestTimezoneConversion(t *testing.T) {
1688-
zones := []string{"UTC", "US/Central", "US/Pacific", "Local"}
1685+
zones := []string{"UTC", "America/New_York", "Asia/Hong_Kong", "Local"}
16891686

16901687
// Regression test for timezone handling
16911688
tzTest := func(dbt *DBTest) {
16921689
// Create table
16931690
dbt.mustExec("CREATE TABLE test (ts TIMESTAMP)")
16941691

16951692
// Insert local time into database (should be converted)
1696-
usCentral, _ := time.LoadLocation("US/Central")
1697-
reftime := time.Date(2014, 05, 30, 18, 03, 17, 0, time.UTC).In(usCentral)
1693+
newYorkTz, _ := time.LoadLocation("America/New_York")
1694+
reftime := time.Date(2014, 05, 30, 18, 03, 17, 0, time.UTC).In(newYorkTz)
16981695
dbt.mustExec("INSERT INTO test VALUE (?)", reftime)
16991696

17001697
// Retrieve time from DB
@@ -1713,7 +1710,7 @@ func TestTimezoneConversion(t *testing.T) {
17131710
// Check that dates match
17141711
if reftime.Unix() != dbTime.Unix() {
17151712
dbt.Errorf("times do not match.\n")
1716-
dbt.Errorf(" Now(%v)=%v\n", usCentral, reftime)
1713+
dbt.Errorf(" Now(%v)=%v\n", newYorkTz, reftime)
17171714
dbt.Errorf(" Now(UTC)=%v\n", dbTime)
17181715
}
17191716
}
@@ -3541,6 +3538,15 @@ func TestConnectionAttributes(t *testing.T) {
35413538

35423539
dbt := &DBTest{t, db}
35433540

3541+
var varName string
3542+
var varValue string
3543+
err := dbt.db.QueryRow("SHOW VARIABLES LIKE 'performance_schema'").Scan(&varName, &varValue)
3544+
if err != nil {
3545+
t.Fatalf("error: %s", err.Error())
3546+
}
3547+
if varValue != "ON" {
3548+
t.Skipf("Performance schema is not enabled. skipping")
3549+
}
35443550
queryString := "SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs WHERE PROCESSLIST_ID = CONNECTION_ID()"
35453551
rows := dbt.mustQuery(queryString)
35463552
defer rows.Close()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /