9 lines
1.8 KiB
JavaScript
9 lines
1.8 KiB
JavaScript
import fs from 'node:fs';import {spawn,spawnSync}from'node:child_process';import assert from'node:assert/strict';
|
|
const php='C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',script='scripts/sgf-stock-final-concurrency.php',run=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),dir=run.root+'/private/receipt-composition-b4093c6f6707/stock-final-concurrency-20261110';
|
|
const sync=mode=>{const r=spawnSync(php,[script,mode],{encoding:'utf8'});assert.equal(r.status,0,r.stdout+r.stderr);assert.match(r.stdout,/"passed":true/);return r.stdout;};
|
|
if(fs.existsSync(dir+'/result.json')){const proof=JSON.parse(fs.readFileSync(dir+'/result.json'));assert.equal(proof.passed,true);console.log(JSON.stringify({passed:true,reused:true,proof:dir+'/result.json'}));process.exit();}
|
|
sync('prepare');const first=spawn(php,[script,'first'],{stdio:'pipe'});let errors='';first.stdout.on('data',d=>errors+=d);first.stderr.on('data',d=>errors+=d);const ended=new Promise(resolve=>first.once('exit',resolve));
|
|
try{const deadline=Date.now()+10000;while(!fs.existsSync(dir+'/locked.json')&&Date.now()<deadline)await new Promise(r=>setTimeout(r,50));assert(fs.existsSync(dir+'/locked.json'),'first writer lock');const second=spawn(php,[script,'second'],{stdio:'pipe'});let secondOutput='';second.stdout.on('data',d=>secondOutput+=d);second.stderr.on('data',d=>secondOutput+=d);const exit=await new Promise(r=>second.once('exit',r));assert.equal(exit,0,secondOutput);const blocked=JSON.parse(fs.readFileSync(dir+'/second.json'));assert.match(blocked.result.message,/ocupada/);assert(blocked.elapsed_seconds>=4.5&&blocked.elapsed_seconds<12);}
|
|
finally{fs.writeFileSync(dir+'/release','release only this synthetic first transaction');assert.equal(await ended,0,errors);}
|
|
console.log(sync('recover').trim());
|