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 8c010ea

Browse files
rushermethane
authored andcommitted
test stability improvement.
* ensuring performance schema is enabled when testing some performance schema results * Added logic to check if the default collation is overridden by the server 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"
1 parent 21ef4c6 commit 8c010ea

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

‎driver_test.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,13 +1630,46 @@ func TestCollation(t *testing.T) {
16301630
}
16311631

16321632
runTests(t, tdsn, func(dbt *DBTest) {
1633+
// see https://mariadb.com/kb/en/setting-character-sets-and-collations/#changing-default-collation
1634+
// when character_set_collations is set for the charset, it overrides the default collation
1635+
// so we need to check if the default collation is overridden
1636+
forceExpected := expected
1637+
var defaultCollations string
1638+
err := dbt.db.QueryRow("SELECT @@character_set_collations").Scan(&defaultCollations)
1639+
if err == nil {
1640+
// Query succeeded, need to check if we should override expected collation
1641+
collationMap := make(map[string]string)
1642+
pairs := strings.Split(defaultCollations, ",")
1643+
for _, pair := range pairs {
1644+
parts := strings.Split(pair, "=")
1645+
if len(parts) == 2 {
1646+
collationMap[parts[0]] = parts[1]
1647+
}
1648+
}
1649+
1650+
// Get charset prefix from expected collation
1651+
parts := strings.Split(expected, "_")
1652+
if len(parts) > 0 {
1653+
charset := parts[0]
1654+
if newCollation, ok := collationMap[charset]; ok {
1655+
forceExpected = newCollation
1656+
}
1657+
}
1658+
}
1659+
16331660
var got string
16341661
if err := dbt.db.QueryRow("SELECT @@collation_connection").Scan(&got); err != nil {
16351662
dbt.Fatal(err)
16361663
}
16371664

16381665
if got != expected {
1639-
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
1666+
if forceExpected != expected {
1667+
if got != forceExpected {
1668+
dbt.Fatalf("expected forced connection collation %s but got %s", forceExpected, got)
1669+
}
1670+
} else {
1671+
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
1672+
}
16401673
}
16411674
})
16421675
}
@@ -1685,16 +1718,16 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
16851718
}
16861719

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

16901723
// Regression test for timezone handling
16911724
tzTest := func(dbt *DBTest) {
16921725
// Create table
16931726
dbt.mustExec("CREATE TABLE test (ts TIMESTAMP)")
16941727

16951728
// 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)
1729+
newYorkTz, _ := time.LoadLocation("America/New_York")
1730+
reftime := time.Date(2014, 05, 30, 18, 03, 17, 0, time.UTC).In(newYorkTz)
16981731
dbt.mustExec("INSERT INTO test VALUE (?)", reftime)
16991732

17001733
// Retrieve time from DB
@@ -1713,7 +1746,7 @@ func TestTimezoneConversion(t *testing.T) {
17131746
// Check that dates match
17141747
if reftime.Unix() != dbTime.Unix() {
17151748
dbt.Errorf("times do not match.\n")
1716-
dbt.Errorf(" Now(%v)=%v\n", usCentral, reftime)
1749+
dbt.Errorf(" Now(%v)=%v\n", newYorkTz, reftime)
17171750
dbt.Errorf(" Now(UTC)=%v\n", dbTime)
17181751
}
17191752
}
@@ -3541,6 +3574,15 @@ func TestConnectionAttributes(t *testing.T) {
35413574

35423575
dbt := &DBTest{t, db}
35433576

3577+
var varName string
3578+
var varValue string
3579+
err := dbt.db.QueryRow("SHOW VARIABLES LIKE 'performance_schema'").Scan(&varName, &varValue)
3580+
if err != nil {
3581+
t.Fatalf("error: %s", err.Error())
3582+
}
3583+
if varValue != "ON" {
3584+
t.Skipf("Performance schema is not enabled. skipping")
3585+
}
35443586
queryString := "SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs WHERE PROCESSLIST_ID = CONNECTION_ID()"
35453587
rows := dbt.mustQuery(queryString)
35463588
defer rows.Close()

0 commit comments

Comments
(0)

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