mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 14:56:42 +00:00
GODT-1034 More tolerant connection speed detection
This commit is contained in:
committed by
Jakub Cuth
parent
4d000c2376
commit
8b436186a4
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user