(b *testing.B)
| 390 | } |
| 391 | |
| 392 | func BenchmarkPersistentCaller_Call(b *testing.B) { |
| 393 | log.SetLevel(log.InfoLevel) |
| 394 | utils.RemoveAll(PubKeyStorePath + "*") |
| 395 | defer utils.RemoveAll(PubKeyStorePath + "*") |
| 396 | utils.RemoveAll(publicKeyStore + "*") |
| 397 | defer utils.RemoveAll(publicKeyStore + "*") |
| 398 | |
| 399 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*15) |
| 400 | defer cancel() |
| 401 | err := utils.WaitForPorts(ctx, "127.0.0.1", []int{ |
| 402 | 2230, |
| 403 | }, time.Millisecond*200) |
| 404 | |
| 405 | if err != nil { |
| 406 | log.Fatalf("wait for port ready timeout: %v", err) |
| 407 | } |
| 408 | |
| 409 | _, testFile, _, _ := runtime.Caller(0) |
| 410 | confFile := filepath.Join(filepath.Dir(testFile), "../../test/node_standalone/config.yaml") |
| 411 | privateKeyPath := filepath.Join(filepath.Dir(testFile), "../../test/node_standalone/private.key") |
| 412 | |
| 413 | conf.GConf, _ = conf.LoadConfig(confFile) |
| 414 | log.Debugf("GConf: %#v", conf.GConf) |
| 415 | // reset the once |
| 416 | route.Once.Reset() |
| 417 | _ = GetSessionPoolInstance().Close() |
| 418 | route.InitKMS(publicKeyStore) |
| 419 | |
| 420 | addr := conf.GConf.ListenAddr // see ../test/node_standalone/config.yaml |
| 421 | masterKey := []byte("") |
| 422 | dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true) |
| 423 | |
| 424 | server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht}) |
| 425 | if err != nil { |
| 426 | b.Fatal(err) |
| 427 | } |
| 428 | |
| 429 | _ = server.InitRPCServer(addr, privateKeyPath, masterKey) |
| 430 | go server.Serve() |
| 431 | |
| 432 | client := NewPersistentCaller(conf.GConf.BP.NodeID) |
| 433 | node1 := proto.NewNode() |
| 434 | _ = node1.InitNodeCryptoInfo(100 * time.Millisecond) |
| 435 | node1.Addr = "1.1.1.1:1" |
| 436 | |
| 437 | reqA := &proto.PingReq{ |
| 438 | Node: *node1, |
| 439 | } |
| 440 | |
| 441 | respA := new(proto.PingResp) |
| 442 | err = client.Call("DHT.Ping", reqA, respA) |
| 443 | if err != nil { |
| 444 | b.Fatal(err) |
| 445 | } |
| 446 | log.Debugf("respA: %v", respA) |
| 447 | |
| 448 | client = NewPersistentCaller(conf.GConf.BP.NodeID) |
| 449 | b.Run("benchmark Persistent Call Nil", func(b *testing.B) { |
nothing calls this directly
no test coverage detected