From 5d4f6610e35977c20ddfbb11e29152fe81288399 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Tue, 25 Oct 2022 15:13:02 +0800 Subject: [PATCH] fix: set tcp keep alive --- docs/CHANGELOG.md | 2 +- hrp/pkg/uixt/client.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5a0bfdd0..6bf0da18 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,7 +2,7 @@ ## v4.3.0 (2022-10-24) -Release hrp sub package `uixt` to support iOS/Android UI automation 🎉 +Release hrp sub package `uixt` to support iOS/Android UI automation testing 🎉 - feat: support iOS UI automation with [WebDriverAgent] and [gwda] - feat: support Android UI automation with [uiautomator2] and [guia2] diff --git a/hrp/pkg/uixt/client.go b/hrp/pkg/uixt/client.go index 5ebd9309..cedbdff8 100644 --- a/hrp/pkg/uixt/client.go +++ b/hrp/pkg/uixt/client.go @@ -93,10 +93,18 @@ func (wd *Driver) httpRequest(method string, rawURL string, rawBody []byte) (raw } func convertToHTTPClient(conn net.Conn) *http.Client { + // set tcp keep alive + tcpConn := conn.(*net.TCPConn) + if err := tcpConn.SetKeepAlive(true); err != nil { + log.Error().Err(err).Msg("set tcp keep alive failed") + } + if err := tcpConn.SetKeepAlivePeriod(5 * time.Second); err != nil { + log.Error().Err(err).Msg("set tcp keep alive period failed") + } return &http.Client{ Transport: &http.Transport{ DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { - return conn, nil + return tcpConn, nil }, }, Timeout: 0,