MayamaTakeshi / sip-lab

A node module that helps to write SIP functional tests
3 stars 2 forks source link

Consider running sip-lab as an external process #55

Open MayamaTakeshi opened 6 months ago

MayamaTakeshi commented 6 months ago

Regarding #41 and #54, I think it is not worthy to spend time with them.

Instead I think we should build different versions of the app based on architecture, keep statically linking all libs that we need and add some code in index.js to spawn sip-lab as an external process and communicate with it:

const { spawn } = require('child_process');

// Start an external process
const externalProcess = spawn('external_program', ['arg1', 'arg2']);

// Listen for output from the external process
externalProcess.stdout.on('data', (data) => {
  console.log(`Received data from external process: ${data}`);
});

// Send data to the external process
externalProcess.stdin.write('Data to send to external process');

// Handle errors
externalProcess.on('error', (err) => {
  console.error(`Error in external process: ${err}`);
});

// Handle process exit
externalProcess.on('close', (code) => {
  console.log(`External process exited with code ${code}`);
});
MayamaTakeshi commented 6 months ago

Also, we might need to force the external process to terminate if our script dies:

const { spawn } = require('child_process');

const externalProcess = spawn('external_program', ['arg1', 'arg2']);

// Handle Node.js process exit
process.on('exit', () => {
  // Kill the spawned process when the Node.js process exits
  externalProcess.kill();
});