本文整理汇总了Golang中testing.B.Fail方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Fail方法的具体用法?Golang B.Fail怎么用?Golang B.Fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Fail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkGetCustomerAddresses
func BenchmarkGetCustomerAddresses(b *testing.B) {
shopID := cart.InsertTestData()
if shopID == nil {
b.Error("failed to create a shop")
b.Fail()
}
val := shopID.Hex()
qs := make(url.Values, 0)
qs.Add("shop", val)
cust := cart.Customer{
ShopId: *shopID,
FirstName: "Alex",
LastName: "Ninneman",
Email: time.Now().Format(time.RFC3339Nano) + "@gmail.com",
Password: "password",
}
if err := cust.Insert("http://www.example.com"); err != nil {
b.Error(err.Error())
b.Fail()
}
(&httprunner.BenchmarkOptions{
Method: "GET",
Route: "/shopify/customers/" + cust.Id.Hex() + "/addresses",
ParameterizedRoute: "/shopify/customers/:id/addresses",
Handler: GetAddresses,
QueryString: &qs,
Runs: b.N,
}).RequestBenchmark()
}
示例2: BenchmarkRemoteClient
func BenchmarkRemoteClient(t *testing.B) {
t.SetParallelism(4)
t.RunParallel(func(pb *testing.PB) {
for pb.Next() {
for i := 0; i < t.N; i++ {
p := packet.NewPacket(1, []byte("echo"))
tmp := clientManager.FindRemoteClients([]string{"a"}, func(groupid string, c *client.RemotingClient) bool {
return false
})
_, err := tmp["a"][0].WriteAndGet(*p, 500*time.Millisecond)
clientf.WriteFlow.Incr(1)
if nil != err {
t.Fail()
log.Printf("WAIT RESPONSE FAIL|%s\n", err)
} else {
// log.Printf("WAIT RESPONSE SUCC|%s\n", string(resp.([]byte)))
}
}
}
})
}
示例3: BenchmarkToJSON2
func BenchmarkToJSON2(b *testing.B) {
var (
vals = make([]bench3.Bench, b.N)
res = []byte{}
err error
)
for i := 0; i < b.N; i++ {
vals[i] = bench3.NewBench("demo", 42, json.Marshal)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
res, err = vals[i].ToJSON()
if err != nil {
b.Logf("Failed test: %d with error: %q", i, err)
b.Fail()
}
}
b.StopTimer()
byteEncoded = res
runtime.GC()
}
示例4: benchAddRemove
func benchAddRemove(amount int, b *testing.B) {
g := New(16)
if len(addRemoveList) > amount {
addRemoveList = addRemoveList[:amount]
}
for n := 0; n < amount; n++ {
if len(addRemoveList) == amount {
break
}
addRemoveList = append(addRemoveList, random())
}
if len(addRemoveList) != amount {
b.Log("len() reports", len(addRemoveList), "want", amount)
b.Fail()
return
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
for _, s := range addRemoveList {
g.Add(s)
if !g.Remove(s) {
b.Log("failed to remove")
b.Fail()
}
}
}
}
示例5: BenchmarkConvertXgb
// DEBUG: CPU1 - 45ns/op
// DEBUG: CPU2 - 0.75ns/op
func BenchmarkConvertXgb(b *testing.B) {
b.StopTimer()
diameter := int(math.Sqrt(float64(b.N)))
if diameter > 5000 {
diameter = 5000
}
r := image.Rect(0, 0, diameter, diameter)
source := getrgba(r)
target := &xgraphics.Image{
X: nil,
Pixmap: 0,
Pix: make([]uint8, 4*r.Dx()*r.Dy()),
Stride: 4 * r.Dx(),
Rect: r,
Subimg: false,
}
b.StartTimer()
convertRGBAtoXgb(target, source)
b.StopTimer()
if !compareImages(source, target) {
b.Fail()
}
target.Destroy()
}
示例6: BenchmarkClosest1k
func BenchmarkClosest1k(b *testing.B) {
tree := New()
n := 1000
for i := 0; i < n; i++ {
o := random()
tree.Add(o)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
results := make(chan gfx.Boundable)
tree.Closest(nil, results, nil)
nResults := 0
for {
_, ok := <-results
if !ok {
break
}
nResults++
}
if len(results) != n {
b.Log("results", nResults)
b.Log("want", n)
b.Fail()
}
}
}
示例7: BenchmarkUpdateFast
// Ideally should perform much better than both BenchmarkUpdateDumb and
// BenchmarkUpdateWorst.
func BenchmarkUpdateFast(b *testing.B) {
objs := benchObjs
for len(objs) < nUpdateObjects {
objs = append(objs, random())
}
benchObjs = objs
tree := New()
for _, o := range objs {
tree.Add(o)
}
b.ResetTimer()
fail := 0
success := 0
for n := 0; n < b.N; n++ {
oldIndex := n % len(objs)
oldObj := objs[oldIndex]
newObj := offset(oldObj.(gfx.Bounds))
if !tree.Update(oldObj, newObj) {
fail++
} else {
success++
}
objs[oldIndex] = newObj
}
if fail > 0 {
b.Logf("Update failure ratio: fail=%d success=%d.", fail, success)
b.Fail()
}
}
示例8: Benchmark_Logic
// 0.28 ns/op empty
// 32 ns/op with noop just method calls
// Each interop call costs ~30-45ns
func Benchmark_Logic(b *testing.B) {
//data := make([]byte, 10)
//var batch *Batch
//buffer, _ := NewRingBuffer(SINGLE_WRITER, 16, 10)
//defer buffer.Close()
log.Printf("Bench: %d", b.N)
for i := 0; i < b.N; i++ {
buffer, _ := NewRingBuffer(64, 2)
batch, _ := buffer.Claim(1)
//batch.Entry(0).CopyFrom(GetData(10))
//batch.CopyTo(0, )
data := buffer.Entry(batch.SeqNum)
//data := batch.Entry(0)
if data[0] != uint8(10) {
b.Fail()
}
//batch.Publish()
buffer.Publish(batch)
//batch, _ = buffer.Claim(1)
//batch.Entries[0].CopyFrom(data)
//batch.Publish()
buffer.Close()
}
}
示例9: BenchmarkMessages
func BenchmarkMessages(b *testing.B) {
numMessages := 10000
adapter.count = numMessages
var err error
//b.ResetTimer()
for i := 0; i < numMessages; i++ {
go func() {
//emsg := createTestBlock()
emsg := createTestChaincodeEvent("0xffffffff", "event1")
if err = producer.Send(emsg); err != nil {
b.Fail()
b.Logf("Error sending message %s", err)
}
}()
}
select {
case <-adapter.notfy:
case <-time.After(5 * time.Second):
b.Fail()
b.Logf("timed out on messge")
}
}
示例10: BenchmarkQuery
func BenchmarkQuery(t *testing.B) {
log.Printf("BenchmarkQuery|Query|Start...")
t.StopTimer()
cleanSnapshot("./snapshot/")
snapshot := NewMessageStore("./snapshot/", 1, 10, 1*time.Second, traverse)
snapshot.Start()
for j := 0; j < 20; j++ {
d := []byte(fmt.Sprintf("%d|hello snapshot", j))
cmd := NewCommand(-1, fmt.Sprint(j), d, nil)
snapshot.Append(cmd)
}
time.Sleep(2 * time.Second)
t.StartTimer()
i := 0
for ; i < t.N; i++ {
id := int64(rand.Intn(20)) + 1
_, err := snapshot.Query(id)
if nil != err {
log.Printf("Query|%s|%d\n", err, id)
t.Fail()
break
}
}
t.StopTimer()
snapshot.Destory()
cleanSnapshot("./snapshot/")
t.StartTimer()
}
示例11: BenchmarkRandomStr
func BenchmarkRandomStr(b *testing.B) {
for i := 0; i < b.N; i++ {
if len(RandomStr()) != 10 {
b.Fail()
}
}
}
示例12: BenchmarkTermIndexSearch
func BenchmarkTermIndexSearch(b *testing.B) {
ctx := BenchContext("TermIndexAdd")
termSpace := 100
numDocs := 1000
numTermsPerDoc := 5
ti := NewTermIndex()
for i := 0; i < numDocs; i++ {
id := "id" + strconv.Itoa(i)
for j := 0; j < numTermsPerDoc; j++ {
term := strconv.Itoa((i * j) % termSpace)
ti.Add(ctx, term, id)
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
term1 := strconv.Itoa(i % termSpace)
term2 := strconv.Itoa((i + 1) % termSpace)
term3 := strconv.Itoa((i + 2) % termSpace)
_, err := ti.Search(ctx, []string{term1, term2, term3})
if err != nil {
b.Fail()
}
}
}
示例13: BenchmarkReadWay
func BenchmarkReadWay(b *testing.B) {
b.StopTimer()
cache_dir, _ := ioutil.TempDir("", "imposm3_test")
defer os.RemoveAll(cache_dir)
cache, err := newWaysCache(cache_dir)
if err != nil {
b.Fatal()
}
defer cache.Close()
way := &element.Way{}
for i := 0; i < b.N; i++ {
way.Id = int64(i)
cache.PutWay(way)
}
b.StartTimer()
for i := int64(0); i < int64(b.N); i++ {
if coord, err := cache.GetWay(i); err != nil || coord.Id != i {
b.Fail()
}
}
}
示例14: BenchmarkFetchNodeHourlyPubsize
func BenchmarkFetchNodeHourlyPubsize(b *testing.B) {
b.StopTimer()
lgr := newTestLogger(b)
nsqdOpts := nsqd.NewOptions()
nsqdOpts.TCPAddress = "127.0.0.1:0"
nsqdOpts.HTTPAddress = "127.0.0.1:0"
nsqdOpts.BroadcastAddress = "127.0.0.1"
nsqdOpts.Logger = lgr
_, _, nsqd1, nsqd1Srv := mustStartNSQD(nsqdOpts)
b.Logf("nsqd started")
time.Sleep(100 * time.Millisecond)
var topicNames []string
for i := 0; i < 1000; i++ {
//create sample topics
topicName := fmt.Sprintf("Topic-Benchmark%04d", i)
nsqd1.GetTopic(topicName, 0)
topicNames = append(topicNames, topicName)
b.Logf("Topic %s created.", topicName)
}
type TopicHourlyPubsizeStat struct {
TopicName string `json:"topic_name"`
TopicPartition string `json:"topic_partition"`
HourlyPubsize int64 `json:"hourly_pub_size"`
}
type NodeHourlyPubsizeStats struct {
TopicHourlyPubsizeList []*TopicHourlyPubsizeStat `json:"node_hourly_pub_size_stats"`
}
b.StartTimer()
for i := 0; i < b.N; i++ {
endpoint := fmt.Sprintf("http://%s/message/historystats", nsqd1Srv.ctx.httpAddr.String())
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
b.Errorf("Fail to get message history from %s - %s", endpoint, err)
b.Fail()
}
client := http.Client{}
resp, err := client.Do(req)
var nodeHourlyPubsizeStats NodeHourlyPubsizeStats
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &nodeHourlyPubsizeStats)
resp.Body.Close()
b.Logf("Node topics hourly pub size list: %d", len(nodeHourlyPubsizeStats.TopicHourlyPubsizeList))
}
b.StopTimer()
//cleanup
for _, topicName := range topicNames {
err := nsqd1.DeleteExistingTopic(topicName, 0)
if err != nil {
b.Logf("Fail to delete topic: %s", topicName)
}
}
}
示例15: BenchmarkQuadFilter
func BenchmarkQuadFilter(b *testing.B) {
l, err := Open(small)
if err != nil {
return
}
l.BuildQuadTree()
var points [rounds]int
for i := 0; i < rounds; i++ {
x, y := (l.MaxX-l.MinX)/2, (l.MaxY-l.MinY)/2
xbuf := (l.MaxX - l.MinX) * 0.01 * float64(i)
ybuf := (l.MaxY - l.MinY) * 0.01 * float64(i)
l.SetFilter(x-xbuf, x+xbuf, y-ybuf, y+ybuf)
f := 0
for {
_, err := l.GetNextPoint()
if err != nil {
break
}
f++
}
points[i] = f
}
for i := 1; i < rounds; i++ {
if points[i-1] > points[i] {
b.Fail()
}
}
}