use the timescale factor for flow control tests on CIs

This commit is contained in:
Marten Seemann 2018-01-03 10:26:50 +07:00
parent 843a0786fc
commit b7b50572eb
3 changed files with 19 additions and 7 deletions

View file

@ -1,6 +1,8 @@
package flowcontrol
import (
"os"
"strconv"
"time"
"github.com/lucas-clemente/quic-go/congestion"
@ -9,6 +11,16 @@ import (
. "github.com/onsi/gomega"
)
// on the CIs, the timing is a lot less precise, so scale every duration by this factor
func scaleDuration(t time.Duration) time.Duration {
scaleFactor := 1
if f, err := strconv.Atoi(os.Getenv("TIMESCALE_FACTOR")); err == nil { // parsing "" errors, so this works fine if the env is not set
scaleFactor = f
}
Expect(scaleFactor).ToNot(BeZero())
return time.Duration(scaleFactor) * t
}
var _ = Describe("Base Flow controller", func() {
var controller *baseFlowController
@ -118,7 +130,7 @@ var _ = Describe("Base Flow controller", func() {
It("increases the window size if read so fast that the window would be consumed in less than 4 RTTs", func() {
bytesRead := controller.bytesRead
rtt := 200 * time.Millisecond
rtt := scaleDuration(20 * time.Millisecond)
setRtt(rtt)
// consume more than 2/3 of the window...
dataRead := receiveWindowSize*2/3 + 1
@ -139,7 +151,7 @@ var _ = Describe("Base Flow controller", func() {
// this test only makes sense if a window update is triggered before half of the window has been consumed
Expect(protocol.WindowUpdateThreshold).To(BeNumerically(">", 1/3))
bytesRead := controller.bytesRead
rtt := 200 * time.Millisecond
rtt := scaleDuration(20 * time.Millisecond)
setRtt(rtt)
// consume more than 2/3 of the window...
dataRead := receiveWindowSize*1/3 + 1
@ -158,7 +170,7 @@ var _ = Describe("Base Flow controller", func() {
It("doesn't increase the window size if read too slowly", func() {
bytesRead := controller.bytesRead
rtt := 200 * time.Millisecond
rtt := scaleDuration(20 * time.Millisecond)
setRtt(rtt)
// consume less than 2/3 of the window...
dataRead := receiveWindowSize*2/3 - 1
@ -181,7 +193,7 @@ var _ = Describe("Base Flow controller", func() {
controller.epochStartOffset = controller.bytesRead
controller.AddBytesRead(controller.receiveWindowSize/2 + 1)
}
setRtt(200 * time.Millisecond)
setRtt(scaleDuration(20 * time.Millisecond))
resetEpoch()
controller.maybeAdjustWindowSize()
Expect(controller.receiveWindowSize).To(Equal(2 * oldWindowSize)) // 2000