當前位置: 首頁>>代碼示例>>Golang>>正文


Golang B.Fail方法代碼示例

本文整理匯總了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()
}
開發者ID:ninnemana,項目名稱:API,代碼行數:32,代碼來源:address_test.go

示例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)))
				}
			}
		}

	})
}
開發者ID:materone,項目名稱:turbo,代碼行數:25,代碼來源:remoting_server_test.go

示例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()
}
開發者ID:dlsniper,項目名稱:u,代碼行數:25,代碼來源:bench3_test.go

示例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()
			}
		}
	}
}
開發者ID:pombredanne,項目名稱:rand,代碼行數:27,代碼來源:gridex_test.go

示例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()
}
開發者ID:errnoh,項目名稱:wde-drawbench,代碼行數:28,代碼來源:draw_test.go

示例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()
		}
	}
}
開發者ID:pombredanne,項目名稱:rand,代碼行數:28,代碼來源:distancer_test.go

示例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()
	}
}
開發者ID:pombredanne,項目名稱:rand,代碼行數:34,代碼來源:tree_test.go

示例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()
	}
}
開發者ID:vizidrix,項目名稱:ringbuffer,代碼行數:29,代碼來源:ringbuffer_test.go

示例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")
	}
}
開發者ID:yoshiharay,項目名稱:fabric,代碼行數:26,代碼來源:events_test.go

示例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()

}
開發者ID:hawkchch,項目名稱:kiteq,代碼行數:33,代碼來源:kite_message_store_test.go

示例11: BenchmarkRandomStr

func BenchmarkRandomStr(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if len(RandomStr()) != 10 {
			b.Fail()
		}
	}
}
開發者ID:tenge,項目名稱:gofm,代碼行數:7,代碼來源:doubanfm_test.go

示例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()
		}
	}
}
開發者ID:Comcast,項目名稱:rulio,代碼行數:26,代碼來源:termindex_test.go

示例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()
		}
	}

}
開發者ID:renderless,項目名稱:imposm3,代碼行數:25,代碼來源:osm_test.go

示例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)
		}
	}
}
開發者ID:absolute8511,項目名稱:nsq,代碼行數:60,代碼來源:http_test.go

示例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()
		}
	}
}
開發者ID:HarishArelli,項目名稱:go-lidar,代碼行數:28,代碼來源:las_test.go


注:本文中的testing.B.Fail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。