当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.B类代码示例

本文整理汇总了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)
		}
	}
}
开发者ID:eghobo,项目名称:kubedash,代码行数:26,代码来源:request_test.go

示例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)
}
开发者ID:RomanMinkin,项目名称:fasthttp,代码行数:26,代码来源:server_timing_test.go

示例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)
			}
		}
	}
}
开发者ID:berkus,项目名称:completion,代码行数:29,代码来源:cache_test.go

示例4: getParseChi

func getParseChi(b *testing.B) xhandler.HandlerC {
	defer b.ResetTimer()
	if parseChi == nil {
		parseChi = loadChi(parseAPI)
	}
	return parseChi
}
开发者ID:patrickToca,项目名称:xmux,代码行数:7,代码来源:bench_api_test.go

示例5: getParseHTTPRouter

func getParseHTTPRouter(b *testing.B) http.Handler {
	defer b.ResetTimer()
	if parseHTTPRouter == nil {
		parseHTTPRouter = loadHTTPRouter(parseAPI)
	}
	return parseHTTPRouter
}
开发者ID:patrickToca,项目名称:xmux,代码行数:7,代码来源:bench_api_test.go

示例6: BenchmarkHeaderWriteSubset

func BenchmarkHeaderWriteSubset(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		buf.Reset()
		testHeader.WriteSubset(&buf, nil)
	}
}
开发者ID:kostyll,项目名称:gccpy,代码行数:7,代码来源:header_test.go

示例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()
}
开发者ID:JimmyMa,项目名称:gnatsd,代码行数:34,代码来源:bench_test.go

示例8: BenchmarkConcurrentTxStmtQuery

func BenchmarkConcurrentTxStmtQuery(b *testing.B) {
	b.ReportAllocs()
	ct := new(concurrentTxStmtQueryTest)
	for i := 0; i < b.N; i++ {
		doConcurrentTest(b, ct)
	}
}
开发者ID:maqayum,项目名称:gcc-libitm,代码行数:7,代码来源:sql_test.go

示例9: BenchmarkConcurrentRandom

func BenchmarkConcurrentRandom(b *testing.B) {
	b.ReportAllocs()
	ct := new(concurrentRandomTest)
	for i := 0; i < b.N; i++ {
		doConcurrentTest(b, ct)
	}
}
开发者ID:maqayum,项目名称:gcc-libitm,代码行数:7,代码来源:sql_test.go

示例10: BenchmarkTruncIndexNew

func BenchmarkTruncIndexNew(b *testing.B) {
	ids := []string{"banana", "bananaa", "bananab"}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		NewTruncIndex(ids)
	}
}
开发者ID:idvoretskyi,项目名称:coreos-kubernetes,代码行数:7,代码来源:utils_test.go

示例11: BenchmarkSmall

func BenchmarkSmall(t *testing.B) {
	for i := 0; i < t.N; i++ {
		if _, err := ParseString(SmallJson); err != nil {
			t.Fatal(err)
		}
	}
}
开发者ID:gobwas,项目名称:json.go,代码行数:7,代码来源:parser_test.go

示例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)))
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:7,代码来源:text_parser_test.go

示例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)
	}
}
开发者ID:hajimehoshi,项目名称:ebiten,代码行数:7,代码来源:image_test.go

示例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)
	}
}
开发者ID:hajimehoshi,项目名称:ebiten,代码行数:7,代码来源:image_test.go

示例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()
	}
}
开发者ID:BramGruneir,项目名称:cockroach,代码行数:29,代码来源:client_bench_test.go


注:本文中的testing.B类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。