Skip to content

Commit a5d281d

Browse files
authored
Merge pull request #2991 from Johonsoy/fix_example_run_error
test: optimize database connection test logic
2 parents 28daf87 + f3358a9 commit a5d281d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

_example/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"database/sql"
1919
"fmt"
2020
"testing"
21+
"time"
2122

2223
_ "github.com/go-sql-driver/mysql"
2324
"github.com/gocraft/dbr/v2"
@@ -42,6 +43,8 @@ func TestExampleUsersDisabled(t *testing.T) {
4243
main()
4344
}()
4445

46+
// Wait for the database to start
47+
time.Sleep(1 * time.Second)
4548
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
4649
require.NoError(t, err)
4750
require.NoError(t, conn.Ping())
@@ -60,7 +63,6 @@ func TestExampleRootUserEnabled(t *testing.T) {
6063
go func() {
6164
main()
6265
}()
63-
6466
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
6567
require.NoError(t, err)
6668
require.ErrorContains(t, conn.Ping(), "User not found")
@@ -82,7 +84,6 @@ func TestExampleLoadedUser(t *testing.T) {
8284
go func() {
8385
main()
8486
}()
85-
8687
conn, err := dbr.Open("mysql", fmt.Sprintf("no_user:@tcp(%s:%d)/%s", address, port, dbName), nil)
8788
require.NoError(t, err)
8889
require.ErrorContains(t, conn.Ping(), "User not found")
@@ -108,7 +109,6 @@ func TestIssue1621(t *testing.T) {
108109
go func() {
109110
main()
110111
}()
111-
112112
conn, err := dbr.Open("mysql",
113113
fmt.Sprintf("root:@tcp(localhost:%d)/mydb", port), nil)
114114
require.NoError(t, err)

0 commit comments

Comments
 (0)