24 lines
2.6 KiB
PHP
24 lines
2.6 KiB
PHP
<?php
|
|
use App\Services\RetainedGeoJsonCollection;
|
|
$root=dirname(__DIR__);$private=$root.'/storage/app/private/investmoz-v2/portal-audit';
|
|
$plan=json_decode(file_get_contents($private.'/portal-stability-latest.json'),true,512,JSON_THROW_ON_ERROR);
|
|
putenv('STABILITY_QA_MODE=consumers');$app=require $plan['source'].'/tools/portal-stability-runtime.php';
|
|
$comparison=($argv[1]??'')==='compare';$proof=['at'=>gmdate('c'),'mode'=>$comparison?'exact_old_reader_comparison':'destination_128M_streaming','levels'=>[],'active_writes'=>0];
|
|
foreach([1=>11,2=>159,3=>411] as $level=>$expected){
|
|
$file=$plan['source'].'/storage/app/private/investmoz-v2/portal-audit/moz-adm'.$level.'-ine-20190607.geojson';
|
|
$reader=new RetainedGeoJsonCollection($file);$manifest=$reader->manifest();
|
|
throw_unless($manifest['type']==='FeatureCollection'&&$manifest['feature_count']===$expected&&!$manifest['exceededTransferLimit'],RuntimeException::class,'Source manifest differs.');
|
|
$hash=hash_init('sha256');$old=$comparison?json_decode(file_get_contents($file),true,512,JSON_THROW_ON_ERROR):null;$size=0;
|
|
foreach($reader->features() as $i=>$feature){if($comparison)throw_unless($feature===$old['features'][$i],RuntimeException::class,'Feature properties/geometry changed.');
|
|
$json=json_encode($feature,JSON_THROW_ON_ERROR);hash_update($hash,$json."\n");$size=max($size,strlen($json));}
|
|
$proof['levels'][$level]=['expected'=>$expected,'read'=>$manifest['feature_count'],'original_sha256'=>hash_file('sha256',$file),
|
|
'features_sha256'=>hash_final($hash),'largest_encoded_feature_bytes'=>$size,'exact_feature_comparison'=>$comparison];unset($old,$feature,$json,$reader);
|
|
}
|
|
$temp=$plan['source'].'/storage/app/private/invalid-geo-reader-test.json';$refused=0;
|
|
foreach(['{"type":"FeatureCollection","features":[]} trailing','{"type":"FeatureCollection","features":[{]}','{"type":"FeatureCollection","features":[],"features":[]}'] as $invalid){
|
|
file_put_contents($temp,$invalid);try{(new RetainedGeoJsonCollection($temp))->manifest();throw new RuntimeException('Invalid source accepted.');}
|
|
catch(Symfony\Component\HttpKernel\Exception\HttpException $e){throw_unless($e->getStatusCode()===422,RuntimeException::class,'Wrong controlled refusal.');$refused++;}}
|
|
$proof+=['result'=>'passed','malformed_cases_controlled_422'=>$refused,'memory_limit'=>ini_get('memory_limit'),'peak_bytes'=>memory_get_peak_usage(true)];
|
|
file_put_contents($private.'/portal-stability-geo-reader-'.($comparison?'comparison':'128M').'.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));
|
|
echo json_encode($proof,JSON_THROW_ON_ERROR).PHP_EOL;
|