forked from quic-go/quic-go
utils: remove scarcely used time helper functions (#4593)
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InfDuration is a duration of infinite length
|
||||
const InfDuration = time.Duration(math.MaxInt64)
|
||||
|
||||
// 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 min(a, b)
|
||||
}
|
||||
|
||||
// MinTime returns the earlier time
|
||||
func MinTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// MaxTime returns the later time
|
||||
func MaxTime(a, b time.Time) time.Time {
|
||||
if a.After(b) {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Min / Max", func() {
|
||||
It("returns the maximum time", func() {
|
||||
a := time.Now()
|
||||
b := a.Add(time.Second)
|
||||
Expect(MaxTime(a, b)).To(Equal(b))
|
||||
Expect(MaxTime(b, a)).To(Equal(b))
|
||||
})
|
||||
|
||||
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))
|
||||
})
|
||||
})
|
||||
@@ -64,7 +64,7 @@ func (r *RTTStats) PTO(includeMaxAckDelay bool) time.Duration {
|
||||
|
||||
// UpdateRTT updates the RTT based on a new sample.
|
||||
func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
|
||||
if sendDelta == InfDuration || sendDelta <= 0 {
|
||||
if sendDelta <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -101,25 +101,17 @@ var _ = Describe("RTT stats", func() {
|
||||
})
|
||||
|
||||
It("UpdateRTTWithBadSendDeltas", func() {
|
||||
// Make sure we ignore bad RTTs.
|
||||
// base::test::MockLog log;
|
||||
|
||||
initialRtt := (10 * time.Millisecond)
|
||||
initialRtt := 10 * time.Millisecond
|
||||
rttStats.UpdateRTT(initialRtt, 0, time.Time{})
|
||||
Expect(rttStats.MinRTT()).To(Equal(initialRtt))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt))
|
||||
|
||||
badSendDeltas := []time.Duration{
|
||||
0,
|
||||
InfDuration,
|
||||
-1000 * time.Microsecond,
|
||||
}
|
||||
// log.StartCapturingLogs();
|
||||
|
||||
for _, badSendDelta := range badSendDeltas {
|
||||
// SCOPED_TRACE(Message() << "bad_send_delta = "
|
||||
// << bad_send_delta.ToMicroseconds());
|
||||
// EXPECT_CALL(log, Log(LOG_WARNING, _, _, _, HasSubstr("Ignoring")));
|
||||
rttStats.UpdateRTT(badSendDelta, 0, time.Time{})
|
||||
Expect(rttStats.MinRTT()).To(Equal(initialRtt))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(initialRtt))
|
||||
|
||||
Reference in New Issue
Block a user