Skip to content

Commit

Permalink
Chore: Attempt to reduce flakiness in integration tests (grafana#97247)
Browse files Browse the repository at this point in the history
* sqlstore/sqlutil: set sync=OFF for sqlite in tests if wal=true

* testinfra: set max open/idle conn to 2 to match e2e tests
  • Loading branch information
macabu authored and shubhankarunhale committed Dec 27, 2024
1 parent ee6bf7a commit 54b4275
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/services/sqlstore/sqlutil/sqlutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ func sqLite3TestDB() (*TestDB, error) {

ret.ConnStr = "file:" + sqliteDb + "?cache=private&mode=rwc"
if os.Getenv("SQLITE_JOURNAL_MODE") != "false" {
ret.ConnStr += "&_journal_mode=WAL"
// For tests, set sync=OFF for faster commits. Reference: https://www.sqlite.org/pragma.html#pragma_synchronous.
ret.ConnStr += "&_journal_mode=WAL&_synchronous=OFF"
}
ret.Path = sqliteDb

Expand Down
9 changes: 7 additions & 2 deletions pkg/tests/testinfra/testinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,14 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
}
}
}
logSection, err := getOrCreateSection("database")

dbSection, err := getOrCreateSection("database")
require.NoError(t, err)
_, err = dbSection.NewKey("query_retries", fmt.Sprintf("%d", queryRetries))
require.NoError(t, err)
_, err = dbSection.NewKey("max_open_conn", "2")
require.NoError(t, err)
_, err = logSection.NewKey("query_retries", fmt.Sprintf("%d", queryRetries))
_, err = dbSection.NewKey("max_idle_conn", "2")
require.NoError(t, err)

cfgPath := filepath.Join(cfgDir, "test.ini")
Expand Down

0 comments on commit 54b4275

Please sign in to comment.