TestRefillMonitor.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. define('APP_ID', 'refill_stat');
  4. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  5. require_once(BASE_ROOT_PATH . '/global.php');
  6. require_once(BASE_CORE_PATH . '/lrlz.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
  9. require_once(BASE_HELPER_PATH . '/queue/iqueue.php');
  10. require_once(BASE_HELPER_PATH . '/queue/monitor.php');
  11. require_once(BASE_HELPER_PATH . '/refill/util.php');
  12. use refill;
  13. class TestRefillMonitor extends TestCase
  14. {
  15. public static function setUpBeforeClass(): void
  16. {
  17. Base::run_util();
  18. }
  19. //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillMonitor::testPushMessage)( .*)?$/" --test-suffix TestRefillMonitor.php /var/www/html/test
  20. public function testPushMessage()
  21. {
  22. $gen_mchids = function ($start,$count)
  23. {
  24. $result = [];
  25. for($i = $start; $i < $start + $count; ++$i) {
  26. $result[] = $i;
  27. }
  28. return $result;
  29. };
  30. $time = strtotime("2022-07-27");
  31. $mchids = $gen_mchids(1092,200);
  32. foreach (range(1, 50000) as $i)
  33. {
  34. $cur_time = $time + rand(0, 86400);
  35. $pos = rand(0, 200);
  36. $mchid = $mchids[$pos];
  37. refill\util::monitor_submit($mchid, 10, 4, 98.5, $cur_time);
  38. refill\util::monitor_submit($mchid, 20, 5, 98.5, $cur_time);
  39. refill\util::monitor_submit($mchid, 30, 6, 98.5, $cur_time);
  40. refill\util::monitor_submit($mchid, 50, 4, 98.5, $cur_time);
  41. refill\util::monitor_submit($mchid, 100, 5, 98.5, $cur_time);
  42. refill\util::monitor_submit($mchid, 200, 6, 98.5, $cur_time);
  43. refill\util::monitor_submit($mchid, 300, 5, 98.5, $cur_time);
  44. refill\util::monitor_submit($mchid, 500, 6, 98.5, $cur_time);
  45. }
  46. }
  47. public function testPushEqualMsg()
  48. {
  49. $time = strtotime("2022-07-27");
  50. $cur_time = $time + 10;
  51. for($i = 0; $i < 10; $i++) {
  52. $mchid = 1092;
  53. refill\util::monitor_submit($mchid, 100, 5, 98.5, $cur_time);
  54. }
  55. }
  56. public function testAddMTimes()
  57. {
  58. $mtimes = [
  59. 10299 => 1657831019,
  60. 10304 => 1657833490,
  61. 10250 => 1657840392,
  62. 1093 => 1657848109,
  63. 10105 => 1657848384,
  64. 10281 => 1657849018,
  65. 10201 => 1657849281,
  66. 10284 => 1657849396,
  67. 10283 => 1657849577,
  68. 10264 => 1657849608,
  69. 10289 => 1657850505,
  70. 10131 => 1657850569,
  71. 10222 => 1657850581,
  72. 10263 => 1657850658,
  73. 10184 => 1657850674,
  74. 10305 => 1657850680
  75. ];
  76. $val = json_encode($mtimes);
  77. wkcachex('stat-earliest-ordertime', $val, 'refill-');
  78. }
  79. public function testDebts()
  80. {
  81. $debts_stoped = function ($mchid)
  82. {
  83. if($mchid > 0)
  84. {
  85. $ret = rcache('merchant-debt-judge', 'refill-',"{$mchid}");
  86. if(empty($ret)) {
  87. return false;
  88. }
  89. $stoped = intval($ret[$mchid]);
  90. return ($stoped === 1);
  91. }
  92. else {
  93. return false;
  94. }
  95. };
  96. wcache('merchant-debt-judge', [1 => 1], 'refill-');
  97. $ret = $debts_stoped(3);
  98. $ret = $debts_stoped(1);
  99. $ret = $debts_stoped(2);
  100. wcache('merchant-debt-judge', [2 => 0], 'refill-');
  101. $ret = $debts_stoped(2);
  102. }
  103. public function testQuality()
  104. {
  105. $quality = new refill\quality_ploy();
  106. $all = $quality->qualities(refill\Quality::DefSuccess);
  107. refill\PolicyUtil::mixed_remove_last(refill\Quality::DefSuccess, [1, 2], $all);
  108. }
  109. public function testMChannels()
  110. {
  111. $mchannel = new refill\mchannel();
  112. }
  113. public function testDbConnect()
  114. {
  115. $mod = Model();
  116. $result = $mod->table('refill_order')->limit(10)->select();
  117. Log::record('',Log::DEBUG);
  118. }
  119. }