MCPcopy
hub / github.com/sqlc-dev/sqlc / waitForMySQL

Function waitForMySQL

cmd/sqlc-test-setup/main.go:670–683  ·  view source on GitHub ↗

waitForMySQL polls until MySQL accepts connections or the timeout expires.

(timeout time.Duration)

Source from the content-addressed store, hash-verified

668
669// waitForMySQL polls until MySQL accepts connections or the timeout expires.
670func waitForMySQL(timeout time.Duration) error {
671 deadline := time.Now().Add(timeout)
672 for time.Now().Before(deadline) {
673 // Try connecting without password (fresh) or with password (already configured)
674 if exec.Command("mysqladmin", "-u", "root", "ping").Run() == nil {
675 return nil
676 }
677 if exec.Command("mysqladmin", "-h", "127.0.0.1", "-u", "root", "-pmysecretpassword", "ping").Run() == nil {
678 return nil
679 }
680 time.Sleep(500 * time.Millisecond)
681 }
682 return fmt.Errorf("timed out after %s waiting for mysql", timeout)
683}
684
685func verifyMySQL() error {
686 log.Println("verifying mysql connection")

Callers 1

startMySQLDaemonFunction · 0.70

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected