GODT-1034 More tolerant connection speed detection

This commit is contained in:
Michal Horejsek
2021-02-09 12:46:24 +01:00
committed by Jakub Cuth
parent 4d000c2376
commit 8b436186a4
2 changed files with 7 additions and 3 deletions

View File

@ -455,18 +455,22 @@ func (c *client) readAllMinSpeed(data io.Reader, cancelRequest context.CancelFun
})
// speedCheckSeconds controls how often we check the transfer speed.
const speedCheckSeconds = 3
// Note that connection can be unstable, on average very fast, but can be
// idle for few seconds; or that API can take its time before sending
// another data, e.g., API can send some data and take some time before
// processing and sending the rest of the response.
const speedCheckSeconds = 30
var buffer bytes.Buffer
for {
_, err := io.CopyN(&buffer, data, c.cm.config.MinBytesPerSecond*speedCheckSeconds)
timer.Stop()
timer.Reset(speedCheckSeconds * time.Second)
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
timer.Reset(speedCheckSeconds * time.Second)
}
return ioutil.ReadAll(&buffer)

View File

@ -172,7 +172,7 @@ func TestClient_FirstReadTimeout(t *testing.T) {
func TestClient_MinSpeedTimeout(t *testing.T) {
finish, c := newTestServerCallbacks(t,
routeSlow(4*time.Second), // 1 second longer than the minimum transfer speed poll time.
routeSlow(31*time.Second), // 1 second longer than the minimum transfer speed poll time.
)
defer finish()