replace zxq.co/ripple/hanayo
This commit is contained in:
43
vendor/github.com/valyala/fasthttp/bytebuffer_test.go
generated
vendored
Normal file
43
vendor/github.com/valyala/fasthttp/bytebuffer_test.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package fasthttp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestByteBufferAcquireReleaseSerial(t *testing.T) {
|
||||
testByteBufferAcquireRelease(t)
|
||||
}
|
||||
|
||||
func TestByteBufferAcquireReleaseConcurrent(t *testing.T) {
|
||||
concurrency := 10
|
||||
ch := make(chan struct{}, concurrency)
|
||||
for i := 0; i < concurrency; i++ {
|
||||
go func() {
|
||||
testByteBufferAcquireRelease(t)
|
||||
ch <- struct{}{}
|
||||
}()
|
||||
}
|
||||
|
||||
for i := 0; i < concurrency; i++ {
|
||||
select {
|
||||
case <-ch:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatalf("timeout!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testByteBufferAcquireRelease(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
b := AcquireByteBuffer()
|
||||
b.B = append(b.B, "num "...)
|
||||
b.B = AppendUint(b.B, i)
|
||||
expectedS := fmt.Sprintf("num %d", i)
|
||||
if string(b.B) != expectedS {
|
||||
t.Fatalf("unexpected result: %q. Expecting %q", b.B, expectedS)
|
||||
}
|
||||
ReleaseByteBuffer(b)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user