Skip to content

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

2.5 KB
Raw Blame
import test from 'node:test';import assert from 'node:assert/strict';
import {commandFaultAdapter,validateCommandTarget,executeFaultCommand} from '../server/command-faults.mjs';
const target={adapter:'command',environment:'local',serviceType:'redis',commandAction:'outage',recoveryMode:'restore',workingDirectory:'/tmp',timeoutSeconds:1,triggerCommand:'true',restoreCommand:'true',readyCommand:'true',faultCheckCommand:'true'};
test('custom commands require explicit supervisor opt-in and complete restoration configuration',()=>{delete process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS;assert.throws(()=>validateCommandTarget(target),/disabled/);process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS='true';assert.throws(()=>validateCommandTarget({...target,restoreCommand:''}),/restoreCommand/);assert.throws(()=>validateCommandTarget({...target,workingDirectory:'relative'}),/absolute/);assert.ok(validateCommandTarget({...target,recoveryMode:'self-recovering',restoreCommand:''}));});
test('adapter independently checks initial health, activation and restoration',async()=>{process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS='true';const calls=[];const adapter=commandFaultAdapter(target,{execute:async(_,field)=>{calls.push(field);if(field==='faultCheckCommand')throw new Error('not down');}});const before=await adapter.probe();await adapter.apply();assert.equal(await adapter.isDown(),false);await adapter.restore(before);assert.equal(await adapter.verify(before),true);assert.deepEqual(calls,['readyCommand','triggerCommand','faultCheckCommand','restoreCommand','readyCommand']);});
test('self-recovering targets do not execute a restore command',async()=>{const calls=[];const adapter=commandFaultAdapter({...target,recoveryMode:'self-recovering'},{execute:async(_,f)=>calls.push(f)});await adapter.restore();assert.deepEqual(calls,[]);});
test('shell command failures and timeouts omit raw output and terminate process groups',async()=>{await assert.rejects(executeFaultCommand({...target,triggerCommand:'echo private-output; exit 7'},'triggerCommand'),/exit 7/);const started=Date.now();await assert.rejects(executeFaultCommand({...target,triggerCommand:'sleep 30 & wait'},'triggerCommand'),/timed out/);assert.ok(Date.now()-started<3000);});

test('disabling command execution preserves readable saved configuration',()=>{delete process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS;assert.ok(validateCommandTarget(target,{requireEnabled:false}));assert.throws(()=>commandFaultAdapter(target),/disabled/);process.env.LOADTEST_ALLOW_CUSTOM_COMMANDS='true';});