add websocket server to this dir. fix stuff for client

This commit is contained in:
2024-10-30 15:12:52 -05:00
parent f8152c6db8
commit 4886bc5b1f
3058 changed files with 1201180 additions and 2 deletions

View File

@ -0,0 +1,23 @@
#!/usr/bin/env node
/******************************************************************************
Grandchild process used to test process group signals. It conditionally ignores SIGINTs in order to emulate programs that catch and discard them.
******************************************************************************/
var heedSignal = (process.argv[2] === 'true');
var waitMillis = parseInt(process.argv[3]);
if (!heedSignal) {
process.on('SIGINT', function () {
// ignore it
});
}
setTimeout(function () {
// disconnect IPC so can exit when stdout, stderr,
// child processes, and other resources complete.
process.disconnect();
process.exit(0);
}, waitMillis);
process.send('ready');

View File

@ -0,0 +1,92 @@
#!/usr/bin/env node
/******************************************************************************
Child process that installs node-cleanup for testing in situations that may entail forking a grandchild process in the same process group. It accepts a single argument of serialized JSON having the following (FlowType) structure:
{
grandchild: boolean; // whether to fork a grandchild process
grandchildHeedsSIGINT: boolean; // whether grandchild heeds SIGINT
messages: object|null; // messages argument for nodeCleanup()
exception: boolean; // whether to throw an uncaught exception
skipTermination: boolean; // true => cleanup handler returns false
exitReturn: 'true'|'undefined'; // value that cleanup handler should
// return to indicate whether the process should exit
maxDuration: number; // max duration of process in millisecs
}
exitReturn indicates the type of value that the cleanup handler returns to indicate whether the process should exit on SIGINT. Ideally, the handler would always return a boolean, but for backwards compatibility, for compatibility with the Stackoverflow solution, and to allow programmers some room for laziness when there are no child processes, an undefined return value also indicates 'true'.
This process implements the WCE solution described for SIGINT at https://www.cons.org/cracauer/sigint.html. That is, the process ignores a SIGINT received while a nested process is running, but sends a SIGINT to itself after a nested process terminates with SIGINT. SIGQUIT is not handled this way because it is not expected that child processes would override and ignore it.
The process writes behavioral results to stdout for comparison with expectations. The output includes space-delimited strings from the following list, ordered in the string by their order of occurrence:
cleanup - child's cleanup handler was called and performed cleanup
skipped_cleanup - child's cleanup handler was called for SIGINT but
did not perform cleanup because a child was running.
grandchild=<reason> - grandchild exited for the given reason, which is
either an integer exit code or the string name of a signal
The process also writes to stderr for comparison with expectations.
******************************************************************************/
//// MODULES //////////////////////////////////////////////////////////////////
var path = require('path');
var fork = require('child_process').fork;
var nodeCleanup = require('../../');
//// CONFIGURATION ////////////////////////////////////////////////////////////
var config = JSON.parse(process.argv[2]);
var grandchildFile = path.resolve(__dirname, "./grandchild.js");
var grandchildMaxDuration = Math.round(config.maxDuration*0.5);
//// STATE ////////////////////////////////////////////////////////////////////
var grandchild = null;
//// MAIN /////////////////////////////////////////////////////////////////////
nodeCleanup(function (exitCode, signal) {
var reason = (exitCode !== null ? exitCode : signal);
if (grandchild !== null && reason === 'SIGINT') {
process.stdout.write('skipped_cleanup ');
return false;
}
process.stdout.write('cleanup ');
if (config.skipTermination) {
nodeCleanup.uninstall(); // don't cleanup again
return false;
}
if (config.exitReturn === 'true')
return true;
}, config.messages);
setTimeout(function () {
// disconnect IPC so can exit when stdout, stderr,
// child processes, and other resources complete.
process.disconnect();
if (config.exception)
throw new Error("unexpected exception");
process.exit(0);
}, config.maxDuration);
if (config.grandchild) {
grandchild = fork(grandchildFile, [
config.grandchildHeedsSIGINT,
grandchildMaxDuration
]);
grandchild.on('message', function (msg) {
if (msg === 'ready')
process.send('ready');
});
grandchild.on('exit', function (exitCode, signal) {
grandchild = null; // allow process to heed forthcoming SIGINT
process.stdout.write('grandchild='+
(exitCode !== null ? exitCode : signal) +' ');
if (signal === 'SIGINT')
process.kill(process.pid, signal);
});
}
else
process.send('ready');

View File

@ -0,0 +1,75 @@
#!/usr/bin/env node
/******************************************************************************
Child process that installs node-cleanup for testing zero, one, or multiple (two) concurrent cleanup handlers. It accepts a single argument of serialized JSON having the following (FlowType) structure:
{
handlers; number; // 0, 1, or 2 concurrent cleanup handlers
messages0: object|null; // messages argument for no-cleanup call, if any
messages1: object|null; // messages argument for 1st nodeCleanup() call
messages2: object|null; // messages argument for 2nd nodeCleanup() call
return1: boolean; // return value of 1st cleanup handler
return2: boolean; // return value of 2nd cleanup handler
uninstall: boolean; // whether to uninstall handlers before test
maxDuration: number; // max duration of process in millisecs
}
The process writes behavioral results to stdout for comparison with expectations. The output includes space-delimited strings from the following list, ordered in the string by their order of occurrence:
cleanup1 - the first cleanup handler ran
cleanup2 - the second cleanup handler ran
The process also writes to stderr for comparison with expectations.
******************************************************************************/
//// MODULES //////////////////////////////////////////////////////////////////
var nodeCleanup = require('../../');
//// CONFIGURATION ////////////////////////////////////////////////////////////
var config = JSON.parse(process.argv[2]);
//// CLEANUP HANDLERS /////////////////////////////////////////////////////////
function cleanup1(exitCode, signal) {
process.stdout.write('cleanup1 ');
if (!config.return1)
nodeCleanup.uninstall(); // don't cleanup again
return config.return1;
}
function cleanup2(exitCode, signal) {
process.stdout.write('cleanup2 ');
if (!config.return2)
nodeCleanup.uninstall(); // don't cleanup again
return config.return2;
}
//// MAIN /////////////////////////////////////////////////////////////////////
if (config.handlers === 0) {
if (config.messages0)
nodeCleanup(config.messages0);
else
nodeCleanup();
}
else {
nodeCleanup(cleanup1, config.messages1);
if (config.handlers > 1)
nodeCleanup(cleanup2, config.messages2);
}
if (config.uninstall)
nodeCleanup.uninstall();
setTimeout(function () {
// disconnect IPC so can exit when stdout, stderr,
// child processes, and other resources complete.
process.disconnect();
if (config.exception)
throw new Error("unexpected exception");
process.exit(0);
}, config.maxDuration);
process.send('ready');