Skip to content

Commit

Permalink
remove sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Lysikov committed Sep 18, 2024
1 parent f16a0af commit 72e1426
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions internal/testing/testdb/starrocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,31 @@ func newStarrocks(opts ...OptionsFunc) (*sql.DB, func(), error) {
)
var db *sql.DB

time.Sleep(20 * time.Second)
// Exponential backoff-retry, because the application in the container
// might not be ready to accept connections yet. Add an extra sleep
// because container take much longer to startup.
pool.MaxWait = time.Minute * 2
if err := pool.Retry(func() error {
var err error
db, err = sql.Open("mysql", dsn)
if err != nil {
return err
}

_, err = db.Exec("CREATE DATABASE IF NOT EXISTS " + STARROCKS_INIT_DB)
if err != nil {
return fmt.Errorf("could not create initial database: %v", err)
}
_, err = db.Exec("USE " + STARROCKS_INIT_DB)
if err != nil {
return fmt.Errorf("could not set default initial database: %v", err)
}

return db.Ping()
},
); err != nil {
return nil, cleanup, fmt.Errorf("could not connect to docker database: %v", err)
}

time.Sleep(30 * time.Second)
_, err = db.Exec("CREATE DATABASE IF NOT EXISTS " + STARROCKS_INIT_DB)
if err != nil {
return nil, cleanup, fmt.Errorf("could not create initial database: %v", err)
}
_, err = db.Exec("USE " + STARROCKS_INIT_DB)
if err != nil {
return nil, cleanup, fmt.Errorf("could not set default initial database: %v", err)
}

return db, cleanup, nil
}

0 comments on commit 72e1426

Please sign in to comment.