nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: knative/pkg
Pull request #1267 (2020-04-30 18:49:00)

Expose the `dialWithBackOff` utility
I'd like to use this to retry TCP dial error in conformance/ingress tests.

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1267#" title="Author self-approved">tcnghia</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[network/OWNERS](https://github.com/knative/pkg/blob/master/network/OWNERS)~~ [tcnghia]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/network/transports.go b/network/transports.go
index b6d9d53d4..f9ab9dac6 100644
--- a/network/transports.go
+++ b/network/transports.go
@@ -55,9 +55,9 @@ var backOffTemplate = wait.Backoff{
 
 var errDialTimeout = errors.New("timed out dialing")
 
-// dialWithBackOff executes `net.Dialer.DialContext()` with exponentially increasing
+// DialWithBackOff executes `net.Dialer.DialContext()` with exponentially increasing
 // dial timeouts. In addition it sleeps with random jitter between tries.
-func dialWithBackOff(ctx context.Context, network, address string) (net.Conn, error) {
+func DialWithBackOff(ctx context.Context, network, address string) (net.Conn, error) {
 	return dialBackOffHelper(ctx, network, address, backOffTemplate, sleepTO)
 }
 
@@ -97,7 +97,7 @@ func newHTTPTransport(connTimeout time.Duration, disableKeepAlives bool) http.Ro
 		DisableKeepAlives:     disableKeepAlives,
 
 		// This is bespoke.
-		DialContext: dialWithBackOff,
+		DialContext: DialWithBackOff,
 	}
 }
 


Test patch:
diff --git a/network/transports_test.go b/network/transports_test.go
index ab4fbdfa8..b7d3ae97b 100644
--- a/network/transports_test.go
+++ b/network/transports_test.go
@@ -74,7 +74,7 @@ func TestHTTPRoundTripper(t *testing.T) {
 
 func TestDialWithBackoff(t *testing.T) {
 	// Nobody's listening on a random port. Usually.
-	c, err := dialWithBackOff(context.Background(), "tcp4", "127.0.0.1:41482")
+	c, err := DialWithBackOff(context.Background(), "tcp4", "127.0.0.1:41482")
 	if err == nil {
 		c.Close()
 		t.Error("Unexpected success dialing")
@@ -97,7 +97,7 @@ func TestDialWithBackoff(t *testing.T) {
 	s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
 	defer s.Close()
 
-	c, err = dialWithBackOff(context.Background(), "tcp4", strings.TrimPrefix(s.URL, "http://"))
+	c, err = DialWithBackOff(context.Background(), "tcp4", strings.TrimPrefix(s.URL, "http://"))
 	if err != nil {
 		t.Fatalf("dial error = %v, want nil", err)
 	}