diff options
author | Erik Dubbelboer <erik@dubbelboer.com> | 2023-07-08 12:40:36 +0200 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2023-07-08 12:40:36 +0200 |
commit | 1c85d43dfea23d49285c8248aff906c965062031 (patch) | |
tree | 38d827e13610680cf36ed01c4354490d7734c492 /http_test.go | |
parent | Avoid nolint:errcheck in header tests (#1589) (diff) | |
download | fasthttp-1c85d43dfea23d49285c8248aff906c965062031.tar.gz fasthttp-1c85d43dfea23d49285c8248aff906c965062031.tar.bz2 fasthttp-1c85d43dfea23d49285c8248aff906c965062031.zip |
Fix round2
- don't limit it to 32 bits
- give it a proper name
- don't over-allocate too much
Diffstat (limited to 'http_test.go')
-rw-r--r-- | http_test.go | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/http_test.go b/http_test.go index d4717f6..370e9aa 100644 --- a/http_test.go +++ b/http_test.go @@ -16,6 +16,7 @@ import ( "strings" "testing" "time" + "unsafe" "github.com/valyala/bytebufferpool" ) @@ -1967,25 +1968,31 @@ func testSetResponseBodyStreamChunked(t *testing.T, body string, trailer map[str } } -func TestRound2(t *testing.T) { +func TestRound2ForSliceCap(t *testing.T) { t.Parallel() - testRound2(t, 0, 0) - testRound2(t, 1, 1) - testRound2(t, 2, 2) - testRound2(t, 3, 4) - testRound2(t, 4, 4) - testRound2(t, 5, 8) - testRound2(t, 7, 8) - testRound2(t, 8, 8) - testRound2(t, 9, 16) - testRound2(t, 0x10001, 0x20000) - testRound2(t, math.MaxInt32-1, math.MaxInt32) + testRound2ForSliceCap(t, 0, 0) + testRound2ForSliceCap(t, 1, 1) + testRound2ForSliceCap(t, 2, 2) + testRound2ForSliceCap(t, 3, 4) + testRound2ForSliceCap(t, 4, 4) + testRound2ForSliceCap(t, 5, 8) + testRound2ForSliceCap(t, 7, 8) + testRound2ForSliceCap(t, 8, 8) + testRound2ForSliceCap(t, 9, 16) + testRound2ForSliceCap(t, 0x10001, 0x20000) + + if unsafe.Sizeof(int(0)) == 4 { + testRound2ForSliceCap(t, math.MaxInt32-1, math.MaxInt32) + } else { + testRound2ForSliceCap(t, math.MaxInt32, math.MaxInt32) + testRound2ForSliceCap(t, math.MaxInt64-1, math.MaxInt64-1) + } } -func testRound2(t *testing.T, n, expectedRound2 int) { - if round2(n) != expectedRound2 { - t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, round2(n), expectedRound2) +func testRound2ForSliceCap(t *testing.T, n, expectedRound2 int) { + if roundUpForSliceCap(n) != expectedRound2 { + t.Fatalf("Unexpected round2(%d)=%d. Expected %d", n, roundUpForSliceCap(n), expectedRound2) } } |