Skip to content

[1.9] test stability improvement. #1699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Daniel Montoya <dsmontoyam at gmail.com>
Daniel Nichter <nil at codenode.com>
Daniël van Eeden <git at myname.nl>
Dave Protasowski <dprotaso at gmail.com>
Diego Dupin <diego.dupin at gmail.com>
Dirkjan Bussink <d.bussink at gmail.com>
DisposaBoy <disposaboy at dby.me>
Egor Smolyakov <egorsmkv at gmail.com>
Expand Down
54 changes: 30 additions & 24 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,35 +1609,32 @@ func TestCollation(t *testing.T) {
t.Skipf("MySQL server not running on %s", netAddr)
}

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

for _, collation := range testCollations {
var expected, tdsn string
if collation != "" {
tdsn = dsn + "&collation=" + collation
expected = collation
} else {
tdsn = dsn
expected = defaultCollation
}

runTests(t, tdsn, func(dbt *DBTest) {
var got string
if err := dbt.db.QueryRow("SELECT @@collation_connection").Scan(&got); err != nil {
dbt.Fatal(err)
}
t.Run(collation, func(t *testing.T) {
tdsn := dsn + "&collation=" + collation
expected := collation

if got != expected {
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
}
runTests(t, tdsn, func(dbt *DBTest) {
var got string
if err := dbt.db.QueryRow("SELECT @@collation_connection").Scan(&got); err != nil {
dbt.Fatal(err)
}
if got != expected {
dbt.Fatalf("expected connection collation %s but got %s", expected, got)
}
})
})
}
}
Expand Down Expand Up @@ -1685,16 +1682,16 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
}

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

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

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

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

dbt := &DBTest{t, db}

var varName string
var varValue string
err := dbt.db.QueryRow("SHOW VARIABLES LIKE 'performance_schema'").Scan(&varName, &varValue)
if err != nil {
t.Fatalf("error: %s", err.Error())
}
if varValue != "ON" {
t.Skipf("Performance schema is not enabled. skipping")
}
queryString := "SELECT ATTR_NAME, ATTR_VALUE FROM performance_schema.session_account_connect_attrs WHERE PROCESSLIST_ID = CONNECTION_ID()"
rows := dbt.mustQuery(queryString)
defer rows.Close()
Expand Down