Skip to content

Commit

Permalink
Fix gh CI failing tests lib/pq#835 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadAhmedGit committed Dec 23, 2023
1 parent 1e3bc0c commit 56465c8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/db_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/SaadAhmedGit/formify/internal/config"
"github.com/SaadAhmedGit/formify/internal/models"
Expand Down Expand Up @@ -35,7 +36,17 @@ func createConnection() (*sqlx.DB, error) {
connStr := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
env.TEST_DB_HOST, env.TEST_DB_PORT, env.TEST_DB_USER, env.TEST_DB_PASSWORD, env.TEST_DB_NAME)
db, err := sqlx.Connect("postgres", connStr)

// https://github.com/lib/pq/issues/835#issuecomment-1774313464
var db *sqlx.DB
for i := 0; i < 20; i++ {
db, err = sqlx.Connect("postgres", connStr)
if err == nil {
break
}

time.Sleep(500 * time.Millisecond)
}
if err != nil {
log.Printf("Failed to connect to database. %s\n", err.Error())
return db, err
Expand Down

0 comments on commit 56465c8

Please sign in to comment.