MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / tryDial

Function tryDial

cmd/root_test.go:1396–1421  ·  view source on GitHub ↗
(method, addr string)

Source from the content-addressed store, hash-verified

1394}
1395
1396func tryDial(method, addr string) (*http.Response, error) {
1397 var (
1398 resp *http.Response
1399 attempts int
1400 err error
1401 )
1402 u, err := url.Parse(addr)
1403 if err != nil {
1404 return nil, err
1405 }
1406 req := &http.Request{Method: method, URL: u}
1407 // Never wait longer than 30 seconds for an HTTP response.
1408 cl := &http.Client{Timeout: 30 * time.Second}
1409 for {
1410 if attempts > 10 {
1411 return resp, err
1412 }
1413 resp, err = cl.Do(req)
1414 if err != nil {
1415 attempts++
1416 time.Sleep(time.Second)
1417 continue
1418 }
1419 return resp, err
1420 }
1421}
1422
1423func TestPrometheusMetricsEndpoint(t *testing.T) {
1424 c := NewCommand(WithDialer(&spyDialer{}))

Callers 5

TestPProfServerFunction · 0.85
TestQuitQuitQuitHTTPPostFunction · 0.85
TestQuitQuitQuitHTTPGetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected