本文整理汇总了Golang中testing.B.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Error方法的具体用法?Golang B.Error怎么用?Golang B.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
}
}
示例2: BenchmarkJsonUnmarshal
func BenchmarkJsonUnmarshal(b *testing.B) {
b.ReportAllocs()
data, err := json.Marshal(&TestStruct)
if err != nil {
b.Error(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
var result CommonStruct
err := json.Unmarshal(data, &result)
if err != nil {
b.Error(err)
}
}
}
示例3: 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)
}
示例4: BenchmarkSingleConn
func BenchmarkSingleConn(b *testing.B) {
srv := NewTestServer(b, 3)
defer srv.Stop()
cluster := testCluster(srv.Address, 3)
// Set the timeout arbitrarily low so that the query hits the timeout in a
// timely manner.
cluster.Timeout = 500 * time.Millisecond
cluster.NumConns = 1
db, err := cluster.CreateSession()
if err != nil {
b.Fatalf("NewCluster: %v", err)
}
defer db.Close()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := db.Query("void").Exec()
if err != nil {
b.Error(err)
return
}
}
})
}
示例5: benchmarkBTreeSetACIDFiler
func benchmarkBTreeSetACIDFiler(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()
wal, err := os.OpenFile(testDbName+".wal", os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err != nil {
b.Fatal(err)
}
defer wal.Close()
filer, err := NewACIDFiler(NewSimpleFileFiler(f), wal)
if err != nil {
b.Error(err)
return
}
benchmarkBTreeSetFiler(b, filer, sz)
}
示例6: BenchmarkDomainCreateSnapshot
func BenchmarkDomainCreateSnapshot(b *testing.B) {
env := newTestEnvironment(b).withDomain()
defer env.cleanUp()
var xml bytes.Buffer
data := newTestSnapshotData()
if err := testSnapshotTmpl.Execute(&xml, data); err != nil {
b.Fatal(err)
}
xmlStr := xml.String()
b.ResetTimer()
for n := 0; n < b.N; n++ {
snap, err := env.dom.CreateSnapshot(xmlStr, SnapCreateDefault)
if err != nil {
b.Error(err)
}
defer snap.Free()
if err := snap.Delete(SnapDeleteDefault); err != nil {
b.Error(err)
}
}
b.StopTimer()
}
示例7: BenchmarkQuery
func BenchmarkQuery(b *testing.B) {
dir1, dir2, ps, clog, err := prepare()
if err != nil {
b.Error(err)
return
}
defer closeAll(dir1, dir2, clog)
b.ResetTimer()
for i := 0; i < b.N; i++ {
gq, _, err := gql.Parse(q1)
if err != nil {
b.Error(err)
return
}
g, err := query.ToSubGraph(gq, ps)
if err != nil {
b.Error(err)
return
}
ch := make(chan error)
go query.ProcessGraph(g, ch, ps)
if err := <-ch; err != nil {
b.Error(err)
return
}
var l query.Latency
_, err = g.ToJson(&l)
if err != nil {
b.Error(err)
return
}
}
}
示例8: BenchmarkRequest
func BenchmarkRequest(b *testing.B) {
m := NewModel(1e6)
m.AddRepo("default", "testdata", nil)
m.ScanRepo("default")
const n = 1000
files := make([]protocol.FileInfo, n)
t := time.Now().Unix()
for i := 0; i < n; i++ {
files[i] = protocol.FileInfo{
Name: fmt.Sprintf("file%d", i),
Modified: t,
Blocks: []protocol.BlockInfo{{100, []byte("some hash bytes")}},
}
}
fc := FakeConnection{
id: "42",
requestData: []byte("some data to return"),
}
m.AddConnection(fc, fc)
m.Index("42", "default", files)
b.ResetTimer()
for i := 0; i < b.N; i++ {
data, err := m.requestGlobal("42", "default", files[i%n].Name, 0, 32, nil)
if err != nil {
b.Error(err)
}
if data == nil {
b.Error("nil data")
}
}
}
示例9: Benchmark_WithValidateBaseUrl
// Benchmark_WithValidateBaseUrl-4 3000 489089 ns/op 188333 B/op 272 allocs/op => with debug enabled
// Benchmark_WithValidateBaseUrl-4 200000 8925 ns/op 2924 B/op 49 allocs/op => no debug
func Benchmark_WithValidateBaseUrl(b *testing.B) {
// todo: there is room for optimization with disabled debugging. too many allocs
store.PkgLog.SetLevel(log.StdLevelInfo)
req, err := http.NewRequest(httputils.MethodGet, "https://corestore.io/customer/comments/view?id=1916#tab=ratings", nil)
if err != nil {
b.Fatal(err)
}
finalHandler := store.WithValidateBaseURL(middlewareConfigReader)(ctxhttp.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return errors.New("This handler should not be called!")
}))
want := "https://www.corestore.io/customer/comments/view?id=1916#tab=ratings"
rec := httptest.NewRecorder()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := finalHandler.ServeHTTPContext(middlewareCtxStoreService, rec, req); err != nil {
b.Error(err)
}
if rec.HeaderMap.Get("Location") != want {
b.Errorf("Have: %s\nWant: %s", rec.HeaderMap.Get("Location"), want)
}
rec.HeaderMap = nil
}
}
示例10: BenchmarkClientFutureParallel
func BenchmarkClientFutureParallel(b *testing.B) {
var err error
conn, err := Connect(server, opts)
if err != nil {
b.Errorf("No connection available")
}
_, err = conn.Replace(spaceNo, []interface{}{uint(1), "hello", "world"})
if err != nil {
b.Errorf("No connection available")
}
b.RunParallel(func(pb *testing.PB) {
exit := false
for !exit {
var fs [N]*Future
var j int
for j = 0; j < N && pb.Next(); j++ {
fs[j] = conn.SelectAsync(spaceNo, indexNo, 0, 1, IterAll, []interface{}{uint(1)})
}
exit = j < N
for j > 0 {
j--
_, err = fs[j].Get()
if err != nil {
b.Error(err)
}
}
}
})
}
示例11: BenchmarkRemoteCollector1000
func BenchmarkRemoteCollector1000(b *testing.B) {
const (
nCollections = 1000
nAnnotations = 100
)
l, err := net.Listen("tcp", ":0")
if err != nil {
b.Fatal(err)
}
cs := NewServer(l, collectorFunc(func(span SpanID, anns ...Annotation) error {
return nil
}))
go cs.Start()
c := NewRemoteCollector(l.Addr().String())
// cc.Collector.(*RemoteCollector).Debug = true
for n := 0; n < b.N; n++ {
for nc := 0; nc < nCollections; nc++ {
id := NewRootSpanID()
anns := make([]Annotation, nAnnotations)
for a := range anns {
anns[a] = Annotation{"k1", []byte("v1")}
}
if err := c.Collect(NewRootSpanID(), anns...); err != nil {
b.Fatalf("Collect(%+v, %v): %s", id, anns, err)
}
}
}
if err := c.Close(); err != nil {
b.Error(err)
}
}
示例12: BenchmarkClientFutureTyped
func BenchmarkClientFutureTyped(b *testing.B) {
var err error
conn, err := Connect(server, opts)
if err != nil {
b.Errorf("No connection available")
}
_, err = conn.Replace(spaceNo, []interface{}{uint(1), "hello", "world"})
if err != nil {
b.Errorf("No connection available")
}
for i := 0; i < b.N; i += N {
var fs [N]*Future
for j := 0; j < N; j++ {
fs[j] = conn.SelectAsync(spaceNo, indexNo, 0, 1, IterAll, []interface{}{uint(1)})
}
for j := 0; j < N; j++ {
var r []tuple
err = fs[j].GetTyped(&r)
if err != nil {
b.Error(err)
}
if len(r) != 1 || r[0].Id != 12 {
b.Errorf("Doesn't match %v", r)
}
}
}
}
示例13: BenchmarkTimedAcquire
func BenchmarkTimedAcquire(b *testing.B) {
const P = 10
const UnitSize = 1000
N := int64(b.N / UnitSize / 4)
s := newTestSemaphore(P)
done := make(chan struct{}, P)
for i := 0; i < P; i++ {
go func() {
for atomic.AddInt64(&N, int64(-1)) > 0 {
for j := 0; j < UnitSize; j++ {
if s.TimedAcquire(1, time.Duration(100)*time.Millisecond) {
s.Release(1)
}
if s.TimedAcquire(2, time.Duration(100)*time.Millisecond) {
s.Release(2)
}
}
}
done <- struct{}{}
}()
}
for i := 0; i < P; i++ {
<-done
}
if err := s.Error(); err != "" {
b.Error(err)
}
}
示例14: BenchmarkRpc
func BenchmarkRpc(b *testing.B) {
var d Daemon
if err := d.init(); err != nil {
b.Fatal(err)
}
go d.serverloop()
defer d.close()
if c, err := jsonrpc.Dial("tcp", fmt.Sprintf("127.0.0.1%s", port)); err != nil {
b.Error(err)
} else {
defer c.Close()
s := time.Now()
for i := 0; i < b.N; i++ {
var a content.CompleteAtArgs
a.Location.Line = 95
a.Location.Column = 45
a.Location.File.Name = "../net/testdata/CompleteSharp.cs"
var cmp1 content.CompletionResult
if err := c.Call("Net.CompleteAt", &a, &cmp1); err != nil {
b.Error(err)
}
}
e := time.Since(s).Seconds() * 1000
b.Logf("%d calls in %f ms = %f ms/call", b.N, e, e/float64(b.N))
}
}
示例15: BenchmarkParsePrefix
func BenchmarkParsePrefix(b *testing.B) {
for n := 0; n < b.N; n++ {
if p := ParsePrefix(prefix); p == nil {
b.Error("parsed prefix should not be nil")
}
}
}