use the minimum of the two peers' max_idle_timeouts

This commit is contained in:
Marten Seemann
2019-12-11 14:03:30 +04:00
parent 8dcca046e3
commit 27549c5665
16 changed files with 89 additions and 52 deletions

View File

@@ -106,6 +106,17 @@ func MinDuration(a, b time.Duration) time.Duration {
return a
}
// MinNonZeroDuration return the minimum duration that's not zero.
func MinNonZeroDuration(a, b time.Duration) time.Duration {
if a == 0 {
return b
}
if b == 0 {
return a
}
return MinDuration(a, b)
}
// AbsDuration returns the absolute value of a time duration
func AbsDuration(d time.Duration) time.Duration {
if d >= 0 {

View File

@@ -89,13 +89,22 @@ var _ = Describe("Min / Max", func() {
Expect(MinPacketNumber(2, 1)).To(Equal(protocol.PacketNumber(1)))
})
It("returns the minimum time", func() {
It("returns the minimum duration", func() {
a := time.Now()
b := a.Add(time.Second)
Expect(MinTime(a, b)).To(Equal(a))
Expect(MinTime(b, a)).To(Equal(a))
})
It("returns the minium non-zero duration", func() {
var a time.Duration
b := time.Second
Expect(MinNonZeroDuration(0, 0)).To(BeZero())
Expect(MinNonZeroDuration(a, b)).To(Equal(b))
Expect(MinNonZeroDuration(b, a)).To(Equal(b))
Expect(MinNonZeroDuration(time.Minute, time.Hour)).To(Equal(time.Minute))
})
It("returns the minium non-zero time", func() {
a := time.Time{}
b := time.Now()