本文整理汇总了Golang中testing.B类的典型用法代码示例。如果您正苦于以下问题:Golang B类的具体用法?Golang B怎么用?Golang B使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了B类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkCheckRetryClosesBody
func BenchmarkCheckRetryClosesBody(t *testing.B) {
count := 0
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
count++
if count%3 == 0 {
w.WriteHeader(http.StatusOK)
return
}
w.Header().Set("Retry-After", "0")
w.WriteHeader(apierrors.StatusTooManyRequests)
}))
defer testServer.Close()
c := NewOrDie(&Config{Host: testServer.URL, Version: testapi.Version(), Username: "user", Password: "pass"})
r := c.Verb("POST").
Prefix("foo", "bar").
Suffix("baz").
Timeout(time.Second).
Body([]byte(strings.Repeat("abcd", 1000)))
for i := 0; i < t.N; i++ {
if _, err := r.DoRaw(); err != nil {
t.Fatalf("Unexpected error: %v %#v", err, err)
}
}
}
示例2: BenchmarkServerHijack
func BenchmarkServerHijack(b *testing.B) {
clientsCount := 1000
requestsPerConn := 10000
ch := make(chan struct{}, b.N)
responseBody := []byte("123")
s := &Server{
Handler: func(ctx *RequestCtx) {
ctx.Hijack(func(c net.Conn) {
// emulate server loop :)
err := ServeConn(c, func(ctx *RequestCtx) {
ctx.Success("foobar", responseBody)
registerServedRequest(b, ch)
})
if err != nil {
b.Fatalf("error when serving connection")
}
})
ctx.Success("foobar", responseBody)
registerServedRequest(b, ch)
},
Concurrency: 16 * clientsCount,
}
req := "GET /foo HTTP/1.1\r\nHost: google.com\r\n\r\n"
benchmarkServer(b, s, clientsCount, requestsPerConn, req)
verifyRequestsServed(b, ch)
}
示例3: BenchmarkCacheComplete
func BenchmarkCacheComplete(b *testing.B) {
b.StopTimer()
paths := DefaultPaths()
if len(paths) == 0 {
b.Skip("No default paths available")
}
tests := []string{"mscorlib.dll", "System.dll"}
c := Cache{paths: paths}
for _, test := range tests {
if _, err := c.Load(test); err != nil {
b.Error(err)
}
}
tests2 := []content.Type{
content.Type{Name: content.FullyQualifiedName{Absolute: "net://type/System.String"}},
}
b.StartTimer()
for i := 0; i < b.N; i++ {
for _, test := range tests2 {
if _, err := c.Complete(&test); err != nil {
b.Error(err)
}
}
}
}
示例4: getParseChi
func getParseChi(b *testing.B) xhandler.HandlerC {
defer b.ResetTimer()
if parseChi == nil {
parseChi = loadChi(parseAPI)
}
return parseChi
}
示例5: getParseHTTPRouter
func getParseHTTPRouter(b *testing.B) http.Handler {
defer b.ResetTimer()
if parseHTTPRouter == nil {
parseHTTPRouter = loadHTTPRouter(parseAPI)
}
return parseHTTPRouter
}
示例6: BenchmarkHeaderWriteSubset
func BenchmarkHeaderWriteSubset(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf.Reset()
testHeader.WriteSubset(&buf, nil)
}
}
示例7: Benchmark_PubFourQueueSub
func Benchmark_PubFourQueueSub(b *testing.B) {
b.StopTimer()
s := runBenchServer()
c := createClientConn(b, "localhost", PERF_PORT)
doDefaultConnect(b, c)
sendProto(b, c, "SUB foo group1 1\r\n")
sendProto(b, c, "SUB foo group1 2\r\n")
sendProto(b, c, "SUB foo group1 3\r\n")
sendProto(b, c, "SUB foo group1 4\r\n")
bw := bufio.NewWriterSize(c, defaultSendBufSize)
sendOp := []byte(fmt.Sprintf("PUB foo 2\r\nok\r\n"))
ch := make(chan bool)
expected := len("MSG foo 1 2\r\nok\r\n") * b.N
go drainConnection(b, c, ch, expected)
b.StartTimer()
for i := 0; i < b.N; i++ {
_, err := bw.Write(sendOp)
if err != nil {
b.Fatalf("Received error on PUB write: %v\n", err)
}
}
err := bw.Flush()
if err != nil {
b.Fatalf("Received error on FLUSH write: %v\n", err)
}
// Wait for connection to be drained
<-ch
b.StopTimer()
c.Close()
s.Shutdown()
}
示例8: BenchmarkConcurrentTxStmtQuery
func BenchmarkConcurrentTxStmtQuery(b *testing.B) {
b.ReportAllocs()
ct := new(concurrentTxStmtQueryTest)
for i := 0; i < b.N; i++ {
doConcurrentTest(b, ct)
}
}
示例9: BenchmarkConcurrentRandom
func BenchmarkConcurrentRandom(b *testing.B) {
b.ReportAllocs()
ct := new(concurrentRandomTest)
for i := 0; i < b.N; i++ {
doConcurrentTest(b, ct)
}
}
示例10: BenchmarkTruncIndexNew
func BenchmarkTruncIndexNew(b *testing.B) {
ids := []string{"banana", "bananaa", "bananab"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
NewTruncIndex(ids)
}
}
示例11: BenchmarkSmall
func BenchmarkSmall(t *testing.B) {
for i := 0; i < t.N; i++ {
if _, err := ParseString(SmallJson); err != nil {
t.Fatal(err)
}
}
}
示例12: BenchmarkUnmarshalText
func BenchmarkUnmarshalText(b *testing.B) {
pb := new(MyMessage)
for i := 0; i < b.N; i++ {
UnmarshalText(benchInput, pb)
}
b.SetBytes(int64(len(benchInput)))
}
示例13: BenchmarkCopyImagePaletted
func BenchmarkCopyImagePaletted(b *testing.B) {
img := image.NewPaletted(image.Rect(0, 0, 4096, 4096), palette.Plan9)
b.ResetTimer()
for i := 0; i < b.N; i++ {
CopyImage(img)
}
}
示例14: BenchmarkCopyImageNRGBA
func BenchmarkCopyImageNRGBA(b *testing.B) {
img := image.NewNRGBA(image.Rect(0, 0, 4096, 4096))
b.ResetTimer()
for i := 0; i < b.N; i++ {
CopyImage(img)
}
}
示例15: BenchmarkReplicaSnapshot
func BenchmarkReplicaSnapshot(b *testing.B) {
defer tracing.Disable()()
storeCfg := TestStoreConfig(nil)
storeCfg.TestingKnobs.DisableSplitQueue = true
stopper := stop.NewStopper()
defer stopper.Stop()
store := createTestStoreWithConfig(b, stopper, &storeCfg)
// We want to manually control the size of the raft log.
store.SetRaftLogQueueActive(false)
rep, err := store.GetReplica(rangeID)
if err != nil {
b.Fatal(err)
}
snapSize := rep.GetMaxBytes()
if err := fillTestRange(rep, snapSize); err != nil {
b.Fatal(err)
}
b.SetBytes(snapSize)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := rep.GetSnapshot(context.Background(), "bench"); err != nil {
b.Fatal(err)
}
rep.CloseOutSnap()
}
}