mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:41:27 +01:00
[GITEA] tests: A workaround for the MySQL collation tests
Because Forgejo run mysqld with `--innodb-flush-method=nosync` to speed
up the test suite, there are situations where a larger, database-wide
operation does not always fully manifest until later, not even when it
is wrapped in a transaction, nor when we use `FLUSH TABLES` and similar
methods.
In the case of the MySQL collation test, this *sometimes* results in the
database still responding with the old collation to a reader, even after
an `ALTER DATABASE ... COLLATE ...`.
In order to be able to still use the aforementioned flag and enjoy its
benefits, add a five second sleep between `db.ConvertDatabaseTable()`
and `db.CheckCollations()` in the `TestDatabaseCollation()` set of
tests.
This is not a fix - I don't think there is one possible -, but a
workaround. If it breaks again, the correct fix will be to remove the
flag from `mysqld` (it's not a supported flag to begin with).
Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
(cherry picked from commit af18ed2ba9
)
This commit is contained in:
parent
5b91430bea
commit
fde08f91fd
1 changed files with 16 additions and 0 deletions
|
@ -5,10 +5,12 @@ package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
|
@ -48,6 +50,8 @@ func TestDatabaseCollation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Default startup makes database collation case-sensitive", func(t *testing.T) {
|
t.Run("Default startup makes database collation case-sensitive", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
r, err := db.CheckCollations(x)
|
r, err := db.CheckCollations(x)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
|
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
|
||||||
|
@ -78,8 +82,12 @@ func TestDatabaseCollation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Convert tables to utf8mb4_bin", func(t *testing.T) {
|
t.Run("Convert tables to utf8mb4_bin", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_bin")()
|
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_bin")()
|
||||||
assert.NoError(t, db.ConvertDatabaseTable())
|
assert.NoError(t, db.ConvertDatabaseTable())
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
r, err := db.CheckCollations(x)
|
r, err := db.CheckCollations(x)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "utf8mb4_bin", r.DatabaseCollation)
|
assert.Equal(t, "utf8mb4_bin", r.DatabaseCollation)
|
||||||
|
@ -95,8 +103,12 @@ func TestDatabaseCollation(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Convert tables to utf8mb4_general_ci", func(t *testing.T) {
|
t.Run("Convert tables to utf8mb4_general_ci", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_general_ci")()
|
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_general_ci")()
|
||||||
assert.NoError(t, db.ConvertDatabaseTable())
|
assert.NoError(t, db.ConvertDatabaseTable())
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
r, err := db.CheckCollations(x)
|
r, err := db.CheckCollations(x)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "utf8mb4_general_ci", r.DatabaseCollation)
|
assert.Equal(t, "utf8mb4_general_ci", r.DatabaseCollation)
|
||||||
|
@ -112,8 +124,12 @@ func TestDatabaseCollation(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Convert tables to default case-sensitive collation", func(t *testing.T) {
|
t.Run("Convert tables to default case-sensitive collation", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
defer test.MockVariableValue(&setting.Database.CharsetCollation, "")()
|
defer test.MockVariableValue(&setting.Database.CharsetCollation, "")()
|
||||||
assert.NoError(t, db.ConvertDatabaseTable())
|
assert.NoError(t, db.ConvertDatabaseTable())
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
r, err := db.CheckCollations(x)
|
r, err := db.CheckCollations(x)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
|
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
|
||||||
|
|
Loading…
Reference in a new issue