Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemtoraman committed Dec 17, 2019
1 parent b40ecef commit 119a93f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions wait/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -60,4 +64,3 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)
}
}
}

0 comments on commit 119a93f

Please sign in to comment.