forked from quic-go/quic-go
add rtt stats
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ReadStream is the read part of a QUIC stream
|
||||
@@ -172,6 +173,22 @@ func MaxInt64(a, b int64) int64 {
|
||||
return b
|
||||
}
|
||||
|
||||
// MaxDuration returns the max duration
|
||||
func MaxDuration(a, b time.Duration) time.Duration {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// AbsDuration returns the absolute value of a time duration
|
||||
func AbsDuration(d time.Duration) time.Duration {
|
||||
if d >= 0 {
|
||||
return d
|
||||
}
|
||||
return -d
|
||||
}
|
||||
|
||||
// RandomBit returns a cryptographically secure random bit (encoded as true / false)
|
||||
func RandomBit() (bool, error) {
|
||||
// ToDo: it's probably more efficient to read a bigger slice of random numbers at once and to cache them somewhere
|
||||
|
||||
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -133,6 +134,15 @@ var _ = Describe("Utils", func() {
|
||||
It("returns the maximum int64", func() {
|
||||
Expect(MaxInt64(5, 7)).To(Equal(int64(7)))
|
||||
})
|
||||
|
||||
It("returns the maximum duration", func() {
|
||||
Expect(MaxDuration(time.Microsecond, time.Nanosecond)).To(Equal(time.Microsecond))
|
||||
})
|
||||
})
|
||||
|
||||
It("returns the abs time", func() {
|
||||
Expect(AbsDuration(time.Microsecond)).To(Equal(time.Microsecond))
|
||||
Expect(AbsDuration(-time.Microsecond)).To(Equal(time.Microsecond))
|
||||
})
|
||||
|
||||
Context("Min", func() {
|
||||
|
||||
Reference in New Issue
Block a user