123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- use PHPUnit\Framework\TestCase;
- define('APP_ID', 'refill_stat');
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_CORE_PATH . '/lrlz.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/queue/iqueue.php');
- require_once(BASE_HELPER_PATH . '/queue/monitor.php');
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- use refill;
- class TestRefillMonitor extends TestCase
- {
- public static function setUpBeforeClass(): void
- {
- Base::run_util();
- }
- public function testLooperChecker()
- {
- // refill\util::loop_order_dec('13911129867',10);
- // refill\util::loop_order_dec('13911129867',10);
- // refill\util::loop_order_dec('13911129867',20);
- // refill\util::loop_order_dec('13911129867',30);
- refill\util::loop_order_inc('13911129867',10);
- refill\util::loop_order_inc('13911129867',10);
- refill\util::loop_order_dec('13911129867',10);
- refill\util::loop_order_dec('13911129867',10);
- refill\util::loop_order_inc('13911129867',20);
- refill\util::loop_order_inc('13911129867',30);
- }
- //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillMonitor::testPushMessage)( .*)?$/" --test-suffix TestRefillMonitor.php /var/www/html/test
- public function testPushMessage()
- {
- $gen_mchids = function ($start,$count)
- {
- $result = [];
- for($i = $start; $i < $start + $count; ++$i) {
- $result[] = $i;
- }
- return $result;
- };
- $time = strtotime("2022-07-27");
- $mchids = $gen_mchids(1092,200);
- foreach (range(1, 50000) as $i)
- {
- $cur_time = $time + rand(0, 86400);
- $pos = rand(0, 200);
- $mchid = $mchids[$pos];
- refill\util::monitor_submit($mchid, 10, 4, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 20, 5, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 30, 6, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 50, 4, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 100, 5, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 200, 6, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 300, 5, 98.5, $cur_time);
- refill\util::monitor_submit($mchid, 500, 6, 98.5, $cur_time);
- }
- }
- //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
- public function testPushEqualMsg()
- {
- $time = strtotime("2022-07-29");
- $cur_time = $time + 10;
- $mchid = 1092;
- $chname = 'ruixunda';
- $spec = 100;
- $card_type = 5;
- $mch_amount = 100;
- $channel_amount = 100;
- $period = 100;
- for($i = 0; $i < 100000; $i++) {
- refill\util::monitor_submit($mchid, $spec, $card_type, $mch_amount, $cur_time);
- refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 1, $cur_time);
- refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 0, $cur_time);
- refill\util::monitor_netchk($chname,1);
- refill\util::monitor_netchk($chname,0);
- refill\util::monitor_commit($chname, $spec, $card_type, $channel_amount,$cur_time);
- refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 1,$cur_time);
- refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 0,$cur_time);
- }
- }
- public function testPushOneMsg()
- {
- $time = strtotime("2022-07-27");
- $cur_time = $time + 10;
- $mchid = 1092;
- $chname = 'ruixunda';
- $spec = 100;
- $card_type = 5;
- $mch_amount = 100;
- $channel_amount = 100;
- $period = 100;
- for($i = 0; $i < 1; $i++) {
- // refill\util::monitor_submit($mchid, $spec, $card_type, $mch_amount, $cur_time);
- // refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 1, $cur_time);
- // refill\util::monitor_callback($mchid, $spec, $card_type, $mch_amount, $channel_amount, 0, $cur_time);
-
- // refill\util::monitor_netchk($chname,1);
- // refill\util::monitor_netchk($chname,0);
- //
- refill\util::monitor_commit($chname, $spec, $card_type, $channel_amount,$cur_time);
- refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 1,$cur_time);
- refill\util::monitor_notify($chname, $spec, $card_type, $channel_amount, $period, 0,$cur_time);
- }
- }
- public function testAddMTimes()
- {
- $mtimes = [
- 10299 => 1657831019,
- 10304 => 1657833490,
- 10250 => 1657840392,
- 1093 => 1657848109,
- 10105 => 1657848384,
- 10281 => 1657849018,
- 10201 => 1657849281,
- 10284 => 1657849396,
- 10283 => 1657849577,
- 10264 => 1657849608,
- 10289 => 1657850505,
- 10131 => 1657850569,
- 10222 => 1657850581,
- 10263 => 1657850658,
- 10184 => 1657850674,
- 10305 => 1657850680
- ];
- $val = json_encode($mtimes);
- wkcachex('stat-earliest-ordertime', $val, 'refill-');
- }
- public function testDebts()
- {
- $debts_stoped = function ($mchid)
- {
- if($mchid > 0)
- {
- $ret = rcache('merchant-debt-judge', 'refill-',"{$mchid}");
- if(empty($ret)) {
- return false;
- }
- $stoped = intval($ret[$mchid]);
- return ($stoped === 1);
- }
- else {
- return false;
- }
- };
- wcache('merchant-debt-judge', [1 => 1], 'refill-');
- $ret = $debts_stoped(3);
- $ret = $debts_stoped(1);
- $ret = $debts_stoped(2);
- wcache('merchant-debt-judge', [2 => 0], 'refill-');
- $ret = $debts_stoped(2);
- }
- public function testQuality()
- {
- $quality = new refill\quality_ploy();
- $all = $quality->qualities(refill\Quality::DefSuccess);
- refill\PolicyUtil::mixed_remove_last(refill\Quality::DefSuccess, [1, 2], $all);
- }
- public function testMChannels()
- {
- $mchannel = new refill\mchannel();
- }
- public function testDbConnect()
- {
- $mod = Model();
- $result = $mod->table('refill_order')->limit(10)->select();
- Log::record('',Log::DEBUG);
- }
- }
|