1
0
Fork 0

Feature 3.4/kill em all (#7590)

This commit is contained in:
Wilfried Goesgens 2018-12-04 09:03:39 +01:00 committed by Jan
parent 743ede87ea
commit d5a64629f8
5 changed files with 72 additions and 13 deletions

View File

@ -10,6 +10,7 @@ const internalMembers = UnitTest.internalMembers;
const fs = require('fs');
const internal = require('internal'); // js/common/bootstrap/modules/internal.js
const inspect = internal.inspect;
const abortSignal = 6;
let testOutputDirectory;
@ -242,10 +243,10 @@ function main (argv) {
}
// run the test and store the result
let r = {}; // result
let res = {}; // result
try {
// run tests
r = UnitTest.unitTest(testSuits, options, testOutputDirectory) || {};
res = UnitTest.unitTest(testSuits, options, testOutputDirectory) || {};
} catch (x) {
print('caught exception during test execution!');
@ -259,18 +260,18 @@ function main (argv) {
print(x);
}
print(JSON.stringify(r));
print(JSON.stringify(res));
}
_.defaults(r, {
_.defaults(res, {
status: false,
crashed: true
});
// whether or not there was an error
try {
fs.write(testOutputDirectory + '/UNITTEST_RESULT_EXECUTIVE_SUMMARY.json', String(r.status), true);
fs.write(testOutputDirectory + '/UNITTEST_RESULT_CRASHED.json', String(r.crashed), true);
fs.write(testOutputDirectory + '/UNITTEST_RESULT_EXECUTIVE_SUMMARY.json', String(res.status), true);
fs.write(testOutputDirectory + '/UNITTEST_RESULT_CRASHED.json', String(res.crashed), true);
} catch (x) {
print('failed to write test result: ' + x.message);
}
@ -279,9 +280,9 @@ function main (argv) {
let j;
try {
j = JSON.stringify(r);
j = JSON.stringify(res);
} catch (err) {
j = inspect(r);
j = inspect(res);
}
fs.write(testOutputDirectory + '/UNITTEST_RESULT.json', j, true);
@ -300,19 +301,25 @@ function main (argv) {
isRocksDb = (options.storageEngine === 'rocksdb');
}
resultsToXml(r, 'UNITTEST_RESULT_' + prefix, isCluster, isRocksDb);
resultsToXml(res, 'UNITTEST_RESULT_' + prefix, isCluster, isRocksDb);
} catch (x) {
print('exception while serializing status xml!');
print(x.message);
print(x.stack);
print(inspect(r));
print(inspect(res));
}
}
// creates yaml like dump at the end
UnitTest.unitTestPrettyPrintResults(r, testOutputDirectory, options);
UnitTest.unitTestPrettyPrintResults(res, testOutputDirectory, options);
return r.status;
let running = require("internal").getExternalSpawned();
let i = 0;
for (i = 0; i < running.length; i++) {
print("Killing remaining process: " + JSON.stringify(running[i]));
print(require("internal").killExternal(running[i].pid, abortSignal));
};
return res.status && running.length === 0;
}
let result = main(ARGUMENTS);

View File

@ -635,6 +635,15 @@ global.DEFINE_MODULE('internal', (function () {
delete global.SYS_EXECUTE_EXTERNAL_AND_WAIT;
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief getExternalSpawned
// //////////////////////////////////////////////////////////////////////////////
if (global.SYS_GET_EXTERNAL_SPAWNED) {
exports.getExternalSpawned = global.SYS_GET_EXTERNAL_SPAWNED;
delete global.SYS_GET_EXTERNAL_SPAWNED;
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief killExternal
// //////////////////////////////////////////////////////////////////////////////

View File

@ -66,7 +66,7 @@ uint64_t TRI_PhysicalMemory;
/// @brief all external processes
////////////////////////////////////////////////////////////////////////////////
static std::vector<ExternalProcess*> ExternalProcesses;
std::vector<ExternalProcess*> ExternalProcesses;
////////////////////////////////////////////////////////////////////////////////
/// @brief lock for protected access to vector ExternalProcesses

View File

@ -127,6 +127,12 @@ struct ExternalProcess {
/// @brief external process status
////////////////////////////////////////////////////////////////////////////////
extern std::vector<ExternalProcess*> ExternalProcesses;
////////////////////////////////////////////////////////////////////////////////
/// @brief external process status
////////////////////////////////////////////////////////////////////////////////
struct ExternalProcessStatus {
TRI_external_status_e _status;
int64_t _exitStatus;

View File

@ -3616,6 +3616,38 @@ static void convertStatusToV8(v8::FunctionCallbackInfo<v8::Value> const& args,
TRI_V8_TRY_CATCH_END;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief lists all running external processes
////////////////////////////////////////////////////////////////////////////////
static void JS_GetExternalSpawned(
v8::FunctionCallbackInfo<v8::Value> const& args) {
TRI_V8_TRY_CATCH_BEGIN(isolate);
v8::HandleScope scope(isolate);
// extract the arguments
if (args.Length() != 0) {
TRI_V8_THROW_EXCEPTION_USAGE("getExternalSpawned()");
}
v8::Handle<v8::Array> spawnedProcesses =
v8::Array::New(isolate, static_cast<int>(ExternalProcesses.size()));
uint32_t i = 0;
for (auto const& process : ExternalProcesses) {
v8::Handle<v8::Object> oneProcess = v8::Object::New(isolate);
ExternalId external;
external._pid = process->_pid;
auto external_status = TRI_CheckExternalProcess(external, false);
convertStatusToV8(args, oneProcess, external_status, external);
spawnedProcesses->Set(i, oneProcess);
i++;
}
TRI_V8_RETURN(spawnedProcesses);
TRI_V8_TRY_CATCH_END
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes a external program
////////////////////////////////////////////////////////////////////////////////
@ -4793,6 +4825,11 @@ void TRI_InitV8Utils(v8::Isolate* isolate, v8::Handle<v8::Context> context,
TRI_AddGlobalFunctionVocbase(isolate,
TRI_V8_ASCII_STRING(isolate, "SYS_SPLIT_WORDS_ICU"),
JS_SplitWordlist);
TRI_AddGlobalFunctionVocbase(isolate,
TRI_V8_ASCII_STRING(isolate, "SYS_GET_EXTERNAL_SPAWNED"),
JS_GetExternalSpawned);
TRI_AddGlobalFunctionVocbase(isolate,
TRI_V8_ASCII_STRING(isolate, "SYS_KILL_EXTERNAL"),
JS_KillExternal);