15 lines
1.1 KiB
JavaScript
15 lines
1.1 KiB
JavaScript
'use strict';
|
|
// Keep the real server entrypoint and OS lifecycle, replacing business startup
|
|
// so this crash test cannot access company systems or production state.
|
|
const fs=require('node:fs'),http=require('node:http'),path=require('node:path');
|
|
const {respondToPing}=require('../../../src/platform/service/ping.cjs');
|
|
const application=require.resolve('../../../src/app/application.cjs');
|
|
require.cache[application]={id:application,filename:application,loaded:true,exports:{async main(){
|
|
const dir=process.env.ORDER_CRASH_TEST_DIR,port=Number(process.env.ORDER_CRASH_TEST_PORT);let ticks=0;
|
|
const server=http.createServer((req,res)=>respondToPing(req,res,{token:process.env.ORDER_SUPERVISOR_TOKEN,instanceId:process.env.ORDER_SUPERVISOR_INSTANCE,startedAt:new Date().toISOString()}));
|
|
await new Promise(resolve=>server.listen(port,'127.0.0.1',resolve));
|
|
fs.writeFileSync(path.join(dir,'child.pid'),String(process.pid));
|
|
const timer=setInterval(()=>fs.writeFileSync(path.join(dir,'ticks'),String(++ticks)),40);
|
|
return {async stop(){clearInterval(timer);await new Promise(resolve=>server.close(resolve));}};
|
|
}}};
|