Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
import test from 'node:test';import assert from 'node:assert/strict';import {mkdtemp,readFile,writeFile,access} from 'node:fs/promises';import path from 'node:path';import os from 'node:os';
const temporary=await mkdtemp(path.join(os.tmpdir(),'scheduled-command-fault-')),down=path.join(temporary,'down');
process.env.LOADTEST_DATA_DIR=temporary;process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS='true';
const seed=JSON.parse(await readFile('../loadtest.config.example.json','utf8'));seed.environment='local';seed.output=path.join(temporary,'artifacts');process.env.LOADTEST_CONFIG_FILE=path.join(temporary,'seed.json');await writeFile(process.env.LOADTEST_CONFIG_FILE,JSON.stringify(seed));
const target={id:'custom-test',label:'Disposable test state',environment:'local',serviceType:'redis',adapter:'command',commandAction:'outage',recoveryMode:'restore',workingDirectory:temporary,timeoutSeconds:1,triggerCommand:`touch '${down}'`,restoreCommand:`rm -f '${down}'`,readyCommand:`test ! -f '${down}'`,faultCheckCommand:`test -f '${down}'`,actions:['outage']};process.env.LOADTEST_FAULT_TARGETS=path.join(temporary,'targets.json');await writeFile(process.env.LOADTEST_FAULT_TARGETS,JSON.stringify([target]));
const {fireFault,restoreFaults,initializeFaults,faultStatus,testFault}=await import('../server/faults.mjs');
const job={id:'load-test',command:'load',status:'running',loadState:'running'},input={targetId:target.id,action:'outage',durationSeconds:1,confirm:`outage ${target.id}`};
async function restored(){await assert.rejects(access(down));assert.equal(faultStatus().blocked,false);}
test('custom faults reject direct and standalone manual execution',async()=>{await assert.rejects(fireFault(job,input),/schedule/);await assert.rejects(testFault({...job,command:'fault-test'},input),/schedule/);});
test('scheduled custom outage restores and records verified recovery',async()=>{const events=[];let activated;const started=new Promise(r=>activated=r);await fireFault(job,input,(_,kind)=>{events.push(kind);if(kind==='fault_started')activated();},()=>job,target);await started;await restoreFaults();await restored();assert.ok(events.includes('fault_restored'));});
test('ambiguous trigger failure still restores infrastructure',async()=>{const failing={...target,triggerCommand:`touch '${down}'; exit 7`};const events=[];let failed;const observed=new Promise(r=>failed=r);await fireFault(job,input,(_,kind)=>{events.push(kind);if(kind==='fault_error')failed();},()=>job,failing);await observed;await restoreFaults();await restored();assert.ok(events.includes('fault_error'));assert.ok(events.includes('fault_restored'));});
test('interrupted persisted custom outage is restored on supervisor startup',async()=>{await writeFile(down,'');await writeFile(path.join(temporary,'fault-ledger.json'),JSON.stringify({id:'interrupted',jobId:'load-test',target,action:'outage',status:'active',before:{ready:true},seconds:1,at:Date.now()}));await initializeFaults(()=>{});await restored();});