conflict_test.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package conflict_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "git.wecise.com/wecise/mring"
  7. "git.wecise.com/wecise/mring/matrix"
  8. "git.wecise.com/wecise/mring/mservice/service"
  9. "git.wecise.com/wecise/odbserver/odb/test"
  10. "git.wecise.com/wecise/odbserver/test/unit/mql/conflict"
  11. "gitee.com/wecisecode/util/logger"
  12. "github.com/stretchr/testify/require"
  13. )
  14. func TestConflict(t *testing.T) {
  15. st := time.Now()
  16. conflict.ConflictTest(t)
  17. logger.Warn("Done", time.Since(st))
  18. }
  19. func TestConflictConcur(t *testing.T) {
  20. logger.DefaultLogger().SetFormat("yyyy-MM-dd HH:mm:ss.SSSSSS [pid] [level] file:line msg", "\n")
  21. logger.DefaultLogger().SetConsoleLevel(logger.INFO)
  22. logger.SetLevel(logger.INFO)
  23. logger.Info(mring.GNode().Name(), "初始化 G ...")
  24. // 等待所有节点就绪,拓扑关系稳定
  25. mring.GNode().MeshReady(1 * time.Second)
  26. conflict.ConflictTest(t)
  27. if true {
  28. return
  29. }
  30. // 提前初始化G,排除G初始化时间
  31. g := test.TestG()
  32. gt := conflict.GT(t, g)
  33. gt.InitG()
  34. if matrix.Config().N == 0 || matrix.Config().N == 1 {
  35. // 测试状态,只有第一节点执行建类操作
  36. logger.Info(mring.GNode().Name(), "初始化 类 ...")
  37. gt.Class(``)
  38. } else {
  39. logger.Info(mring.GNode().Name(), "等待第一测试节点 初始化 类 ...")
  40. }
  41. // 所有测试节点,等待初始化建类完成
  42. if e := mring.GNode().GlobalSync("conflict.class", 60*time.Second); e != nil {
  43. logger.Error(mring.GNode().Name(), "节点间状态同步失败,", e)
  44. require.Nil(t, e, fmt.Sprint("节点间状态同步失败,", e))
  45. return
  46. }
  47. // 开始数据插入
  48. func() {
  49. logger.Info(mring.GNode().Name(), "初始化完成,开始计时")
  50. ts := time.Now()
  51. // info, e := selfmonitor.CPUMonitorStart(nil, "/tmp/bench", -1)
  52. // logger.Info(info)
  53. // if e != nil {
  54. // logger.Errorf(e.Error())
  55. // }
  56. defer func() {
  57. logger.SetLevel(logger.INFO)
  58. logger.Info(mring.GNode().Name(), "数据插入完成,计时结束")
  59. logger.Info(mring.GNode().Name(), "use time", time.Now().Sub(ts).Seconds(), "seconds")
  60. // if e != nil {
  61. // logger.Errorf(e.Error())
  62. // }
  63. // logger.Info(selfmonitor.CPUMonitorStop())
  64. }()
  65. logger.SetLevel(logger.WARN)
  66. gt.DataConcurrent(1000)
  67. // gt.Data()
  68. // gt.Valid()
  69. // conflict.ConflictTest(t)
  70. }()
  71. logger.Info(mring.GNode().Name(), "等待后台数据数据...")
  72. for service.ProcessingCount() > 0 {
  73. time.Sleep(100 * time.Millisecond)
  74. }
  75. logger.Info(mring.GNode().Name(), "等待所有节点完成测试...")
  76. if e := mring.GNode().GlobalSync("conflict.end", 60*time.Second); e != nil {
  77. logger.Error(mring.GNode().Name(), "节点间状态同步失败,", e)
  78. require.Nil(t, e, fmt.Sprint(mring.GNode().Name(), "节点间状态同步失败,", e))
  79. return
  80. }
  81. service.LogStatisticsInfo()
  82. time.Sleep(1 * time.Second)
  83. }