8 lines
3.4 KiB
PHP
8 lines
3.4 KiB
PHP
<?php
|
|
require __DIR__.'/sgf-hr-personnel-proof-bootstrap.php';require __DIR__.'/sgf-hr-personnel-fixture.php';$mode=$argv[1]??'';$directory=$argv[2]??'';if($book!=='regression'||!str_starts_with(str_replace('\\','/',$directory),str_replace('\\','/',$s['root']).'/hp-concurrency-'))throw new LogicException('Regression only');$controller=app(App\Modules\HumanResources\Http\PersonnelController::class);$http=function($token)use($select,$controller,$hp){$select(14);request()->replace(['preview'=>$token]);try{$r=$controller->confirm(request(),$hp);return['status'=>$r->getStatusCode(),'value'=>$r->getData(true)];}catch(Symfony\Component\HttpKernel\Exception\HttpExceptionInterface$e){return['status'=>$e->getStatusCode()];}};
|
|
if($mode==='prepare'){$fixture=$hpFixture('CONCORRENCIA',480);$aKey=$uuid();$bKey=$uuid();$a=$fixture['leave'];$b=array_replace($a,['day_key'=>$fixture['keys']['day11'],'date'=>'2026-11-11']);[$x]=$hpCommand(13,$hpInput('leave',$aKey,0,$a));[$y]=$hpCommand(13,$hpInput('leave',$bKey,0,$b));$ac=$hpPreview(14,$hpInput('leave',$aKey,1,['decision'=>'approved'],'review'));$bc=$hpPreview(14,$hpInput('leave',$bKey,1,['decision'=>'approved'],'review'));file_put_contents($directory.'/cuts.json',json_encode(['first'=>$ac['preview'],'second'=>$bc['preview'],'a_key'=>$aKey,'b_key'=>$bKey,'b_input'=>$b]));echo json_encode(['passed'=>true]).PHP_EOL;exit;}
|
|
if($mode==='inspect'){$pid=json_decode(file_get_contents($directory.'/locked.json'),true)['host_pid'];$rows=$host->select('SELECT pid,wait_event_type,wait_event,pg_blocking_pids(pid) blockers FROM pg_stat_activity WHERE ? = ANY(pg_blocking_pids(pid))',[$pid]);file_put_contents($directory.'/blocking.json',json_encode(['blocker_host_pid'=>$pid,'waiters'=>$rows,'blocker_holds_company_for_update'=>true]));exit;}$cuts=json_decode(file_get_contents($directory.'/cuts.json'),true);
|
|
if($mode==='first'){$host->beginTransaction();try{$out=$http($cuts['first']);if($out['status']!==200)throw new LogicException('First leave review failed');file_put_contents($directory.'/locked.json',json_encode(['host_pid'=>$host->selectOne('SELECT pg_backend_pid() pid')->pid,'status'=>200]));$end=microtime(true)+25;while(!is_file($directory.'/release')&µtime(true)<$end)usleep(50000);$host->commit();}finally{while($host->transactionLevel()>0)$host->rollBack();}exit;}
|
|
if($mode==='second'){$time=microtime(true);$out=$http($cuts['second']);file_put_contents($directory.'/second.json',json_encode(['status'=>$out['status'],'seconds'=>microtime(true)-$time]));exit;}
|
|
if($mode==='recover'){$out=$http($cuts['second']);$again=$http($cuts['first']);$refreshed=null;try{$hpPreview(13,$hpInput('leave',$cuts['b_key'],1,$cuts['b_input']));}catch(Symfony\Component\HttpKernel\Exception\HttpExceptionInterface$e){$refreshed=$e->getStatusCode();}$approved=$host->table('hp_versions')->whereIn('record_key',[$cuts['a_key'],$cuts['b_key']])->where('state','approved')->count();$commands=$host->table('hp_commands')->whereRaw("input->>'record_key' IN (?,?)",[$cuts['a_key'],$cuts['b_key']])->count();$proof=['passed'=>$out['status']===409&&$again['status']===200&&$again['value']['replayed']&&$refreshed===409&&$approved===1&&$commands===3,'after_release'=>$out['status'],'original_replay'=>$again['status'],'new_conference_insufficient_balance'=>$refreshed,'approved_leave_requests'=>$approved,'leave_command_receipts'=>$commands,'regression_only'=>true,'salary_effect'=>false];file_put_contents($directory.'/recovery.json',json_encode($proof));echo json_encode($proof).PHP_EOL;}
|