anticheat_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package anticheat
  2. import (
  3. "sync"
  4. "testing"
  5. "go-common/library/log/infoc"
  6. )
  7. var (
  8. once sync.Once
  9. a *AntiCheat
  10. )
  11. func onceInit() {
  12. a = New(&infoc.Config{
  13. TaskID: "000146",
  14. Addr: "172.16.0.204:514",
  15. Proto: "tcp",
  16. ChanSize: 1,
  17. })
  18. }
  19. // go test -test.v -test.bench Benchmark_InfoAntiCheat
  20. // func Benchmark_InfoAntiCheat(b *testing.B) {
  21. // once.Do(onceInit)
  22. // client := httpx.NewClient(&httpx.ClientConfig{
  23. // App: &conf.App{
  24. // Key: "appKey",
  25. // Secret: "appSecret",
  26. // },
  27. // Timeout: 1,
  28. // })
  29. // params := url.Values{}
  30. // params.Set("access_key", "infoc_access_key")
  31. // params.Set("platform", "android")
  32. // params.Set("build", "1111111")
  33. // req, err := client.NewRequest("GET", "foo-api", "127.1.1.1", params)
  34. // if err != nil {
  35. // b.FailNow()
  36. // }
  37. // c := wctx.NewContext(ctx, req, nil, time.Millisecond*100)
  38. // for j := 0; j < b.N; j++ {
  39. // a.InfoAntiCheat(c, "infoc-test", "ip-address", "mid", "4", "5", "6", "7")
  40. // }
  41. // }
  42. // go test -test.v -test.bench Benchmark_ServiceAntiCheat
  43. func Benchmark_ServiceAntiCheat(b *testing.B) {
  44. once.Do(onceInit)
  45. ac := map[string]string{
  46. "itemType": infoc.ItemTypeAv,
  47. "action": infoc.ActionShare,
  48. "ip": "remoteIP",
  49. "mid": "mid",
  50. "fid": "fid",
  51. "aid": "aid",
  52. "sid": "sid",
  53. "ua": "ua",
  54. "buvid": "buvid",
  55. "refer": "refer",
  56. "url": "infoc-test",
  57. }
  58. for j := 0; j < b.N; j++ {
  59. a.ServiceAntiCheat(ac)
  60. }
  61. }