From 72e1426d3c835fd31e7b1f2750e9797f09e3f96c Mon Sep 17 00:00:00 2001 From: Stanislav Lysikov Date: Wed, 18 Sep 2024 09:48:34 +0300 Subject: [PATCH] remove sleeps --- internal/testing/testdb/starrocks.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/testing/testdb/starrocks.go b/internal/testing/testdb/starrocks.go index f74dcf487..9ab823904 100644 --- a/internal/testing/testdb/starrocks.go +++ b/internal/testing/testdb/starrocks.go @@ -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 }