TestRefillMonitor.php 6.8 KB

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