diff --git a/wait/sql.go b/wait/sql.go index dbfb95de8b..a9acbb4dc8 100644 --- a/wait/sql.go +++ b/wait/sql.go @@ -8,10 +8,11 @@ import ( "time" ) +//ForSQL constructs a new waitForSql strategy for the given driver func ForSQL(port nat.Port, driver string, url func(nat.Port) string) *waitForSql { return &waitForSql{ - Port: port, - URL: url, + Port: port, + URL: url, Driver: driver, } } @@ -23,14 +24,17 @@ type waitForSql struct { startupTimeout time.Duration } +//Timeout sets the maximum waiting time for the strategy after which it'll give up and return an error func (w *waitForSql) Timeout(duration time.Duration) *waitForSql { w.startupTimeout = duration return w } +//WaitUntilReady repeatedly tries to run "SELECT 1" query on the given port using sql and driver. +// If the it doesn't succeed until the timeout value which defaults to 10 seconds, it will return an error func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) { if w.startupTimeout == 0 { - w.startupTimeout = time.Second*10 + w.startupTimeout = time.Second * 10 } ctx, cancel := context.WithTimeout(ctx, w.startupTimeout) defer cancel() @@ -60,4 +64,3 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget) } } } -