mirror of
https://github.com/golang/net.git
synced 2026-03-31 02:17:08 +09:00
The x/net go.mod now depends on go1.23. Change-Id: I24960949d84753f84f75fbdc97b7dfb92191a4d2 Reviewed-on: https://go-review.googlesource.com/c/net/+/664295 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Damien Neil <dneil@google.com>
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
// Copyright 2023 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package quic
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAckDelayFromDuration(t *testing.T) {
|
|
for _, test := range []struct {
|
|
d time.Duration
|
|
ackDelayExponent uint8
|
|
want unscaledAckDelay
|
|
}{{
|
|
d: 8 * time.Microsecond,
|
|
ackDelayExponent: 3,
|
|
want: 1,
|
|
}, {
|
|
d: 1 * time.Nanosecond,
|
|
ackDelayExponent: 3,
|
|
want: 0, // rounds to zero
|
|
}, {
|
|
d: 3 * (1 << 20) * time.Microsecond,
|
|
ackDelayExponent: 20,
|
|
want: 3,
|
|
}} {
|
|
got := unscaledAckDelayFromDuration(test.d, test.ackDelayExponent)
|
|
if got != test.want {
|
|
t.Errorf("unscaledAckDelayFromDuration(%v, %v) = %v, want %v",
|
|
test.d, test.ackDelayExponent, got, test.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAckDelayToDuration(t *testing.T) {
|
|
for _, test := range []struct {
|
|
d unscaledAckDelay
|
|
ackDelayExponent uint8
|
|
want time.Duration
|
|
}{{
|
|
d: 1,
|
|
ackDelayExponent: 3,
|
|
want: 8 * time.Microsecond,
|
|
}, {
|
|
d: 0,
|
|
ackDelayExponent: 3,
|
|
want: 0,
|
|
}, {
|
|
d: 3,
|
|
ackDelayExponent: 20,
|
|
want: 3 * (1 << 20) * time.Microsecond,
|
|
}, {
|
|
d: math.MaxInt64 / 1000,
|
|
ackDelayExponent: 0,
|
|
want: (math.MaxInt64 / 1000) * time.Microsecond,
|
|
}, {
|
|
d: (math.MaxInt64 / 1000) + 1,
|
|
ackDelayExponent: 0,
|
|
want: 0, // return 0 on overflow
|
|
}, {
|
|
d: math.MaxInt64 / 1000 / 8,
|
|
ackDelayExponent: 3,
|
|
want: (math.MaxInt64 / 1000 / 8) * 8 * time.Microsecond,
|
|
}, {
|
|
d: (math.MaxInt64 / 1000 / 8) + 1,
|
|
ackDelayExponent: 3,
|
|
want: 0, // return 0 on overflow
|
|
}} {
|
|
got := test.d.Duration(test.ackDelayExponent)
|
|
if got != test.want {
|
|
t.Errorf("unscaledAckDelay(%v).Duration(%v) = %v, want %v",
|
|
test.d, test.ackDelayExponent, int64(got), int64(test.want))
|
|
}
|
|
}
|
|
}
|