TestRefillMonitor.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillMonitor::testPushEqualMsg)( .*)?$/" --test-suffix TestRefillMonitor.php /var/www/html/test
  48. public function testPushEqualMsg()
  49. {
  50. $time = strtotime("2022-07-29");
  51. $cur_time = $time + 10;
  52. $mchid = 1092;
  53. $chname = 'ruixunda';
  54. $spec = 100;
  55. $card_type = 5;
  56. $mch_amount = 100;
  57. $channel_amount = 100;
  58. $period = 100;
  59. for($i = 0; $i < 100000; $i++) {
  60. refill\util::monitor_submit($mchid, $spec, $card_type, $mch_amount, $cur_time);
  61. refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 1, $cur_time);
  62. refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 0, $cur_time);
  63. refill\util::monitor_netchk($chname,1);
  64. refill\util::monitor_netchk($chname,0);
  65. refill\util::monitor_commit($chname, $spec, $card_type, $channel_amount,$cur_time);
  66. refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 1,$cur_time);
  67. refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 0,$cur_time);
  68. }
  69. }
  70. public function testPushOneMsg()
  71. {
  72. $time = strtotime("2022-07-27");
  73. $cur_time = $time + 10;
  74. $mchid = 1092;
  75. $chname = 'ruixunda';
  76. $spec = 100;
  77. $card_type = 5;
  78. $mch_amount = 100;
  79. $channel_amount = 100;
  80. $period = 100;
  81. for($i = 0; $i < 1; $i++) {
  82. // refill\util::monitor_submit($mchid, $spec, $card_type, $mch_amount, $cur_time);
  83. // refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 1, $cur_time);
  84. // refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 0, $cur_time);
  85. // refill\util::monitor_netchk($chname,1);
  86. // refill\util::monitor_netchk($chname,0);
  87. //
  88. refill\util::monitor_commit($chname, $spec, $card_type, $channel_amount,$cur_time);
  89. refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 1,$cur_time);
  90. refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 0,$cur_time);
  91. }
  92. }
  93. public function testAddMTimes()
  94. {
  95. $mtimes = [
  96. 10299 => 1657831019,
  97. 10304 => 1657833490,
  98. 10250 => 1657840392,
  99. 1093 => 1657848109,
  100. 10105 => 1657848384,
  101. 10281 => 1657849018,
  102. 10201 => 1657849281,
  103. 10284 => 1657849396,
  104. 10283 => 1657849577,
  105. 10264 => 1657849608,
  106. 10289 => 1657850505,
  107. 10131 => 1657850569,
  108. 10222 => 1657850581,
  109. 10263 => 1657850658,
  110. 10184 => 1657850674,
  111. 10305 => 1657850680
  112. ];
  113. $val = json_encode($mtimes);
  114. wkcachex('stat-earliest-ordertime', $val, 'refill-');
  115. }
  116. public function testDebts()
  117. {
  118. $debts_stoped = function ($mchid)
  119. {
  120. if($mchid > 0)
  121. {
  122. $ret = rcache('merchant-debt-judge', 'refill-',"{$mchid}");
  123. if(empty($ret)) {
  124. return false;
  125. }
  126. $stoped = intval($ret[$mchid]);
  127. return ($stoped === 1);
  128. }
  129. else {
  130. return false;
  131. }
  132. };
  133. wcache('merchant-debt-judge', [1 => 1], 'refill-');
  134. $ret = $debts_stoped(3);
  135. $ret = $debts_stoped(1);
  136. $ret = $debts_stoped(2);
  137. wcache('merchant-debt-judge', [2 => 0], 'refill-');
  138. $ret = $debts_stoped(2);
  139. }
  140. public function testQuality()
  141. {
  142. $quality = new refill\quality_ploy();
  143. $all = $quality->qualities(refill\Quality::DefSuccess);
  144. refill\PolicyUtil::mixed_remove_last(refill\Quality::DefSuccess, [1, 2], $all);
  145. }
  146. public function testMChannels()
  147. {
  148. $mchannel = new refill\mchannel();
  149. }
  150. public function testDbConnect()
  151. {
  152. $mod = Model();
  153. $result = $mod->table('refill_order')->limit(10)->select();
  154. Log::record('',Log::DEBUG);
  155. }
  156. }