MCPcopy Index your code
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / WaitForServe

Method WaitForServe

tests/common_test.go:124–148  ·  view source on GitHub ↗

WaitForServe waits until the proxy ready to serve traffic by waiting for a known log message (i.e. "ready for new connections"). Returns any output from the proxy while starting or any errors experienced before the proxy was ready to server.

(ctx context.Context)

Source from the content-addressed store, hash-verified

122// from the proxy while starting or any errors experienced before the proxy was
123// ready to server.
124func (p *ProxyExec) WaitForServe(ctx context.Context) (string, error) {
125 in := bufio.NewReader(p.Out)
126 for {
127 select {
128 case <-ctx.Done():
129 // dump all output and return it as an error
130 all, err := io.ReadAll(in)
131 if err != nil {
132 return "", err
133 }
134 return "", errors.New(string(all))
135 default:
136 }
137 s, err := in.ReadString('\n')
138 if err != nil {
139 return "", err
140 }
141 if strings.Contains(s, "Error") || strings.Contains(s, "error") {
142 return "", errors.New(s)
143 }
144 if strings.Contains(s, "ready for new connections") {
145 return s, nil
146 }
147 }
148}

Callers 2

proxyConnTestWithReadyFunction · 0.80
testHealthCheckFunction · 0.80

Calls 1

DoneMethod · 0.80

Tested by

no test coverage detected