Files
pgsql-broker/tests/integration/connection_test.go
T
warkanum 63a7494982
Integration Tests / integration-test (push) Failing after 57s
fix(tests): update database connection strings for CI
* Use dynamic host and port for Postgres in tests
* Add helper functions for test database host and port
2026-09-18 21:07:28 +02:00

33 lines
746 B
Go

package integration
import (
"database/sql"
"fmt"
"testing"
"time"
_ "github.com/lib/pq"
"github.com/stretchr/testify/require"
)
func TestConnection(t *testing.T) {
connStr := fmt.Sprintf("user=user password=password dbname=broker_test host=%s port=%d sslmode=disable", testDBHost(), testDBPort())
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")
}