Files
pgsql-broker/tests/integration/connection_test.go
T
warkanum 567b1d437c
Integration Tests / integration-test (push) Failing after 1m15s
fix(tests): update database host from localhost to 127.0.0.1
* Adjust connection strings in integration tests for consistency
* Ensure compatibility with CI environments that use IPv4
2026-09-18 20:38:28 +02:00

32 lines
707 B
Go

package integration
import (
"database/sql"
"testing"
"time"
_ "github.com/lib/pq"
"github.com/stretchr/testify/require"
)
func TestConnection(t *testing.T) {
connStr := "user=user password=password dbname=broker_test host=127.0.0.1 port=5433 sslmode=disable"
var db *sql.DB
var err error
for i := 0; i < 10; i++ {
db, err = sql.Open("postgres", connStr)
require.NoError(t, err)
err = db.Ping()
if err == nil {
t.Log("Successfully connected to the database")
db.Close()
return
}
t.Logf("Failed to connect to database (attempt %d), retrying... Error: %v", i+1, err)
time.Sleep(2 * time.Second)
}
require.NoError(t, err, "Failed to connect to database after retries")
}