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


Golang B.Fatal方法代码示例

本文整理汇总了Golang中testing.B.Fatal方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Fatal方法的具体用法?Golang B.Fatal怎么用?Golang B.Fatal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.B的用法示例。


在下文中一共展示了B.Fatal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: BenchmarkGorillaMux

func BenchmarkGorillaMux(b *testing.B) {
	b.StopTimer()
	http.DefaultServeMux = http.NewServeMux()
	r := mux.NewRouter()
	r.HandleFunc("/heroku/resources", fakehandler).
		Methods("POST")
	r.HandleFunc("/heroku/delete", fakehandler).
		Methods("DELETE")
	ts := httptest.NewServer(r)
	defer ts.Close()
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		res, err := http.Post(ts.URL+"/heroku/resources", "text", strings.NewReader(""))
		if err != nil {
			b.Fatal("Post:", err)
		}
		_, err = ioutil.ReadAll(res.Body)
		if err != nil {
			b.Fatal("ReadAll:", err)
		}
	}

	b.StopTimer()
}
开发者ID:kr,项目名称:webx,代码行数:25,代码来源:main_test.go

示例2: BenchmarkConnStress

func BenchmarkConnStress(b *testing.B) {
	const workers = 16

	cluster := createCluster()
	cluster.NumConns = 1
	session := createSessionFromCluster(cluster, b)
	defer session.Close()

	if err := createTable(session, "CREATE TABLE IF NOT EXISTS conn_stress (id int primary key)"); err != nil {
		b.Fatal(err)
	}

	var seed uint64
	writer := func(pb *testing.PB) {
		seed := atomic.AddUint64(&seed, 1)
		var i uint64 = 0
		for pb.Next() {
			if err := session.Query("insert into conn_stress (id) values (?)", i*seed).Exec(); err != nil {
				b.Error(err)
				return
			}
			i++
		}
	}

	b.SetParallelism(workers)
	b.RunParallel(writer)
}
开发者ID:CrowdStrike,项目名称:gocql,代码行数:28,代码来源:stress_test.go

示例3: benchPutItemParallel

func benchPutItemParallel(p, c int, b *testing.B) {
	svc := dynamodb.New(&aws.Config{
		DisableSSL: aws.Bool(true),
	})

	av, err := dynamodbattribute.ConvertToMap(dbItem{Key: "MyKey", Data: "MyData"})
	if err != nil {
		b.Fatal("expect no ConvertToMap errors", err)
	}
	params := &dynamodb.PutItemInput{
		Item:      av,
		TableName: aws.String(testTableName),
	}
	b.N = c

	b.ResetTimer()
	b.SetParallelism(p)
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_, err = svc.PutItem(params)
			if err != nil {
				b.Error("expect no request errors", err)
			}
		}
	})
}
开发者ID:jloper3,项目名称:amazon-ecs-cli,代码行数:26,代码来源:dynamodb_live_test.go

示例4: BenchmarkFilterPatterns

func BenchmarkFilterPatterns(b *testing.B) {
	patterns := []string{
		"sdk/*",
		"*.html",
	}
	lines := extractTestLines(b)
	var c uint

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		c = 0
		for _, line := range lines {
			match, err := filter.List(patterns, line)
			if err != nil {
				b.Fatal(err)
			}

			if match {
				c++
			}
		}

		if c != 22185 {
			b.Fatalf("wrong number of matches: expected 22185, got %d", c)
		}
	}
}
开发者ID:fawick,项目名称:restic,代码行数:28,代码来源:filter_test.go

示例5: 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

示例6: benchmarkBTreeSetRollbackFiler

func benchmarkBTreeSetRollbackFiler(b *testing.B, sz int) {
	dir, testDbName := temp()
	defer os.RemoveAll(dir)

	f, err := os.OpenFile(testDbName, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
	if err != nil {
		b.Fatal(err)
	}

	defer f.Close()

	g := NewSimpleFileFiler(f)
	var filer *RollbackFiler
	if filer, err = NewRollbackFiler(
		g,
		func(sz int64) error {
			if err = g.Truncate(sz); err != nil {
				return err
			}

			return g.Sync()
		},
		g,
	); err != nil {
		b.Error(err)
		return
	}

	benchmarkBTreeSetFiler(b, filer, sz)
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:30,代码来源:btree_test.go

示例7: benchmarkEndToEnd

func benchmarkEndToEnd(dial func() (*Client, error), b *testing.B) {
	b.StopTimer()
	once.Do(startServer)
	client, err := dial()
	if err != nil {
		b.Fatal("error dialing:", err)
	}

	// Synchronous calls
	args := &Args{7, 8}
	procs := runtime.GOMAXPROCS(-1)
	N := int32(b.N)
	var wg sync.WaitGroup
	wg.Add(procs)
	b.StartTimer()

	for p := 0; p < procs; p++ {
		go func() {
			reply := new(Reply)
			for atomic.AddInt32(&N, -1) >= 0 {
				err := client.Call("Arith.Add", args, reply)
				if err != nil {
					b.Fatalf("rpc error: Add: expected no error but got string %q", err.Error())
				}
				if reply.C != args.A+args.B {
					b.Fatalf("rpc error: Add: expected %d got %d", reply.C, args.A+args.B)
				}
			}
			wg.Done()
		}()
	}
	wg.Wait()
}
开发者ID:krasin,项目名称:go-deflate,代码行数:33,代码来源:server_test.go

示例8: BenchmarkAppendRaw

// Benchmarking raw mgo queries.
func BenchmarkAppendRaw(b *testing.B) {
	sess, err := db.Open(Adapter, settings)

	if err != nil {
		b.Fatal(err)
	}

	defer sess.Close()

	artist, err := sess.Collection("artist")
	artist.Truncate()

	driver := sess.Driver().(*mgo.Session)

	mgodb := driver.DB(database)
	col := mgodb.C("artist")

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		err := col.Insert(map[string]string{"name": "Hayao Miyazaki"})
		if err != nil {
			b.Fatal(err)
		}
	}
}
开发者ID:huuzkee-foundation,项目名称:dbcli,代码行数:26,代码来源:database_test.go

示例9: BenchmarkInterfaceAddrs

func BenchmarkInterfaceAddrs(b *testing.B) {
	for i := 0; i < b.N; i++ {
		if _, err := InterfaceAddrs(); err != nil {
			b.Fatal(err)
		}
	}
}
开发者ID:klueska,项目名称:go-akaros,代码行数:7,代码来源:interface_test.go

示例10: BenchmarkLanguage

func BenchmarkLanguage(b *testing.B) {
	b.StopTimer()
	tst := []string{
		"language.go",
		"testdata/main.go",
	}

	var d0 []string
	for _, s := range tst {
		if d, err := ioutil.ReadFile(s); err != nil {
			b.Errorf("Couldn't load file %s: %s", s, err)
		} else {
			d0 = append(d0, string(d))
		}
	}

	b.StartTimer()
	for i := 0; i < b.N; i++ {
		for j := range d0 {
			lp, err := NewLanguageParser("testdata/Go.tmLanguage", d0[j])
			if err != nil {
				b.Fatal(err)
				return
			}
			lp.Parse()
		}
	}
	fmt.Println(util.Prof)
}
开发者ID:gbbr,项目名称:textmate,代码行数:29,代码来源:language_test.go

示例11: BenchmarkAll

func BenchmarkAll(b *testing.B) {
	stds, err := exec.Command("go", "list", "std").Output()
	if err != nil {
		b.Fatal(err)
	}
	b.ResetTimer()
	pkgNames := strings.Fields(string(stds))

	for _, c := range contexts {
		c.Compiler = build.Default.Compiler
	}

	for i := 0; i < b.N; i++ {
		for _, context := range contexts {
			w := NewWalker(context, filepath.Join(build.Default.GOROOT, "src"))
			for _, name := range pkgNames {
				if name != "unsafe" && !strings.HasPrefix(name, "cmd/") {
					pkg, _ := w.Import(name)
					w.export(pkg)
				}
			}
			w.Features()
		}
	}
}
开发者ID:Ericean,项目名称:go,代码行数:25,代码来源:goapi_test.go

示例12: BenchmarkDecodeStruct

func BenchmarkDecodeStruct(b *testing.B) {
	type s1 struct {
		Atom   types.Atom
		priv0  int
		Uint8  uint8
		Uint16 uint16
		Uint32 uint32
		priv1  string
		Byte   byte
		Int    int
		priv2  *s1
		List   []s1
		Binary []byte
	}

	data := []byte{
		131, 104, 8, 100, 0, 12, 116, 104, 105, 115, 32, 105, 115, 32, 97, 116, 111,
		109, 97, 255, 98, 0, 0, 255, 255, 110, 4, 0, 255, 255, 255, 255, 97, 128, 98,
		255, 255, 253, 102, 106, 107, 0, 5, 1, 2, 3, 4, 5,
	}
	in := bytes.NewBuffer(data)

	var v s1
	err := Decode(in, &v)
	if err != nil {
		b.Fatal(err)
	} else if l := in.Len(); l != 0 {
		b.Fatalf("buffer len %d", l)
	}

	for i := 0; i < b.N; i++ {
		in = bytes.NewBuffer(data)
		err = Decode(in, &v)
	}
}
开发者ID:agelin,项目名称:etf,代码行数:35,代码来源:decode_b_test.go

示例13: BenchmarkUsersProd

func BenchmarkUsersProd(b *testing.B) {
	prodfile := "./prods/users.prod"
	text, err := ioutil.ReadFile(prodfile)
	if err != nil {
		b.Fatal(err)
	}
	seed := uint64(time.Now().UnixNano())

	s := parsec.NewScanner(text)
	root, _ := Y(s)
	scope := root.(common.Scope)
	nterms := scope["_nonterminals"].(common.NTForms)
	scope = BuildContext(scope, seed, "./bags", prodfile)

	b.ResetTimer()
	out := 0
	for i := 0; i < b.N; i++ {
		scope = scope.RebuildContext()
		if val, ok := EvalForms("root", scope, nterms["s"]).(string); !ok {
			b.Fatalf("not string `%v`\n", val)
		} else {
			out += len(val)
		}
	}
	b.SetBytes(int64(float64(out) / float64(b.N)))
}
开发者ID:abhi-bit,项目名称:monster,代码行数:26,代码来源:parser_test.go

示例14: BenchmarkAccessorSetReflection

// BenchmarkAccessorSetReflection provides a baseline for accessor performance
func BenchmarkAccessorSetReflection(b *testing.B) {
	obj := &InternalObject{
		InternalTypeMeta{
			Namespace:       "bar",
			Name:            "foo",
			GenerateName:    "prefix",
			UID:             "uid",
			APIVersion:      "a",
			Kind:            "b",
			ResourceVersion: "1",
			SelfLink:        "some/place/only/we/know",
			Labels:          map[string]string{"foo": "bar"},
			Annotations:     map[string]string{"x": "y"},
		},
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		acc, err := meta.Accessor(obj)
		if err != nil {
			b.Fatal(err)
		}
		acc.SetNamespace("something")
	}
	b.StopTimer()
}
开发者ID:40a,项目名称:bootkube,代码行数:27,代码来源:meta_test.go

示例15: benchmarkIterOnBatch

func benchmarkIterOnBatch(b *testing.B, writes int) {
	stopper := stop.NewStopper()
	defer stopper.Stop()

	engine := createTestEngine(stopper)

	for i := 0; i < writes; i++ {
		if err := engine.Put(makeKey(i), []byte(strconv.Itoa(i))); err != nil {
			b.Fatal(err)
		}
	}

	batch := engine.NewBatch()
	defer batch.Close()

	for i := 0; i < writes; i++ {
		if err := batch.Clear(makeKey(i)); err != nil {
			b.Fatal(err)
		}
	}

	r := rand.New(rand.NewSource(5))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		key := makeKey(r.Intn(writes))
		iter := batch.NewIterator(true)
		iter.Seek(key)
		iter.Close()
	}
}
开发者ID:csdigi,项目名称:cockroach,代码行数:31,代码来源:rocksdb_test.go


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