Skip to content
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
7 changes: 5 additions & 2 deletions example/server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -33,7 +36,7 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand Down
7 changes: 5 additions & 2 deletions example/server/gateway/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -33,7 +36,7 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand Down
7 changes: 5 additions & 2 deletions example/server/orchestrator/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand All @@ -33,7 +36,7 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
5 changes: 4 additions & 1 deletion test/integration/extension/queue/mysql/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ services:
ports:
- "3306" # Random ephemeral port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
# Use 127.0.0.1 (TCP) instead of localhost (Unix socket). MySQL treats
# "localhost" as a socket connection, which can be ready before the TCP
# listener — causing dependent services that connect over TCP to fail.
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-proot"]
interval: 5s
timeout: 5s
retries: 10
25 changes: 8 additions & 17 deletions test/testutil/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ func (s *ComposeStack) ServiceHost(serviceName string, containerPort int) (strin
}

// ConnectMySQLService connects to a MySQL service by name in the compose stack.
// Retries the connection and registers cleanup automatically.
// Requires that Up() has been called first — the TCP-based healthcheck in
// docker-compose ensures MySQL is accepting TCP connections before Up() returns.
func (s *ComposeStack) ConnectMySQLService(serviceName string) (*sql.DB, error) {
s.t.Helper()

Expand All @@ -199,24 +200,14 @@ func (s *ComposeStack) ConnectMySQLService(serviceName string) (*sql.DB, error)
return nil, err
}

// Retry connection a few times as MySQL might still be initializing
var db *sql.DB
for i := 0; i < 10; i++ {
db, err = sql.Open("mysql", dsn)
if err != nil {
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
}

if err = db.Ping(); err == nil {
break
}

db.Close()
time.Sleep(1 * time.Second)
db, err := sql.Open("mysql", dsn)
if err != nil {
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
}

if err != nil {
return nil, fmt.Errorf("failed to connect to %s mysql after retries: %w", serviceName, err)
if err = db.Ping(); err != nil {
db.Close()
return nil, fmt.Errorf("failed to ping %s mysql: %w", serviceName, err)
}

port, _ := s.ServicePort(serviceName, 3306) // We already got the port successfully
Expand Down