From 56465c8b2b45d87405e35e3d6c215948da89e798 Mon Sep 17 00:00:00 2001 From: Saad Ahmed Date: Sun, 24 Dec 2023 04:21:06 +0500 Subject: [PATCH] Fix gh CI failing tests https://github.com/lib/pq/issues/835#issuecomment-1774313464 --- tests/db_config.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/db_config.go b/tests/db_config.go index b4d82a0..db6ffb3 100644 --- a/tests/db_config.go +++ b/tests/db_config.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "strings" + "time" "github.com/SaadAhmedGit/formify/internal/config" "github.com/SaadAhmedGit/formify/internal/models" @@ -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