本文整理汇总了Golang中testing.B.Failed方法的典型用法代码示例。如果您正苦于以下问题:Golang B.Failed方法的具体用法?Golang B.Failed怎么用?Golang B.Failed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.B
的用法示例。
在下文中一共展示了B.Failed方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkDelete
func BenchmarkDelete(b *testing.B) {
var objmap interface{}
client := Client{Organization: "yourorgname", Application: "sandbox", Uri: "https://api.usergrid.com"}
params := map[string]string{"limit": strconv.Itoa(500)}
err := client.Get("benchmark", params, JSONResponseHandler(&objmap))
if err != nil {
b.Logf("Test failed: %s\n", err)
b.Fail()
}
omap := objmap.(map[string]interface{})
if omap["entities"] == nil || len(omap["entities"].([]interface{})) == 0 {
b.Logf("Test failed: no entities to delete\n")
b.Fail()
}
entities := omap["entities"].([]interface{})
var entity map[string]interface{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if len(entities) == 0 {
b.Logf("Test failed: we ran out of entities\n")
b.Fail()
continue
}
entity, entities = entities[len(entities)-1].(map[string]interface{}), entities[:len(entities)-1]
err := client.Delete("benchmark/"+entity["uuid"].(string), nil, NOOPResponseHandler(&objmap))
if err != nil {
b.Logf("BenchmarkDelete failed: %s\n", err)
b.Fail()
}
}
if b.Failed() {
str, _ := json.MarshalIndent(objmap, "", " ")
b.Logf("RESPONSE: %s", str)
}
}
示例2: SpawnLocalPipeBench
func SpawnLocalPipeBench(b *testing.B, sender BenchMessageSender, receiver BenchMessageReceiver) {
endClient := make(chan bool)
endServer := make(chan bool)
receiver1, sender1 := libchan.Pipe()
go BenchClient(b, endClient, sender1, sender, b.N)
go BenchServer(b, endServer, receiver1, receiver, b.N)
timeout := time.After(time.Duration(b.N+1) * 50 * time.Millisecond)
for endClient != nil || endServer != nil {
select {
case <-endClient:
if b.Failed() {
b.Fatal("Client failed")
}
endClient = nil
case <-endServer:
if b.Failed() {
b.Fatal("Server failed")
}
endServer = nil
case <-timeout:
if DumpStackOnTimeout {
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
}
b.Fatal("Timeout")
}
}
}
示例3: BenchmarkMarshalJSON
func BenchmarkMarshalJSON(b *testing.B) {
msg := getMessage()
msg.ShellMsgJson.Contents = getTestTuple()
for i := 0; i < b.N; i++ {
_, err := json.Marshal(msg)
if err != nil {
b.Log("Error: ", err)
b.Failed()
}
}
}
示例4: SpawnSpdyProxyBench
func SpawnSpdyProxyBench(b *testing.B, sender BenchMessageSender, receiver BenchMessageReceiver) {
endClient := make(chan bool)
endServer := make(chan bool)
endProxy1 := make(chan bool)
endProxy2 := make(chan bool)
receiver1, sender1, err := testPipe()
if err != nil {
b.Fatalf("Error creating pipe: %s", err)
}
receiver2, sender2, err := testPipe()
if err != nil {
b.Fatalf("Error creating pipe: %s", err)
}
receiver3, sender3, err := testPipe()
if err != nil {
b.Fatalf("Error creating pipe: %s", err)
}
go BenchProxy(b, endProxy1, sender2, receiver1, b.N)
go BenchProxy(b, endProxy2, sender3, receiver2, b.N)
go BenchClient(b, endClient, sender1, sender, b.N)
go BenchServer(b, endServer, receiver3, receiver, b.N)
timeout := time.After(time.Duration(b.N+1) * 200 * time.Millisecond)
for endClient != nil || endServer != nil || endProxy1 != nil || endProxy2 != nil {
select {
case <-endProxy1:
if b.Failed() {
b.Fatal("Proxy failed")
}
endProxy1 = nil
case <-endProxy2:
if b.Failed() {
b.Fatal("Proxy failed")
}
endProxy2 = nil
case <-endClient:
if b.Failed() {
b.Fatal("Client failed")
}
endClient = nil
case <-endServer:
if b.Failed() {
b.Fatal("Server failed")
}
endServer = nil
case <-timeout:
if DumpStackOnTimeout {
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
}
b.Fatal("Timeout")
}
}
}
示例5: BenchmarkParse
func BenchmarkParse(b *testing.B) {
var table = []string{
"insert into t values (1), (2), (3)",
"insert into t values (4), (5), (6), (7)",
"select c from t where c > 2",
}
parser := New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, v := range table {
_, err := parser.Parse(v, "", "")
if err != nil {
b.Failed()
}
}
}
b.ReportAllocs()
}
示例6: BenchmarkPost
func BenchmarkPost(b *testing.B) {
var objmap interface{}
client := Client{Organization: "yourorgname", Application: "sandbox", Uri: "https://api.usergrid.com"}
data := map[string]string{"index": "0", "description": "golang benchmark"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
data["index"] = strconv.Itoa(i)
err := client.Post("benchmark", nil, data, JSONResponseHandler(&objmap))
if err != nil {
b.Logf("BenchmarkPost failed: %s\n", err)
b.Fail()
}
if b.Failed() {
str, _ := json.MarshalIndent(objmap, "", " ")
b.Logf("RESPONSE: %s", str)
}
}
}
示例7: Bench
// Bench runs the given benchmark function. This pre-1.7 implementation renders
// the measurement useless, but allows the code to be compiled at least.
func Bench(b *testing.B, name string, fn func(b *testing.B)) bool {
b.Logf("Running %s...", name)
fn(b)
return b.Failed()
}