From 27e975c016d34ac8d16904f95e445477c9f1ffa4 Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Tue, 24 Jan 2017 14:43:17 +0100 Subject: [PATCH 1/2] Let AgencyComm timeout early, if server is already stopping. --- arangod/Agency/AgencyComm.cpp | 14 ++++++++++++++ arangod/RestServer/ServerFeature.cpp | 1 + arangod/RestServer/ServerFeature.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/arangod/Agency/AgencyComm.cpp b/arangod/Agency/AgencyComm.cpp index 1e1ddf358f..5594fdc557 100644 --- a/arangod/Agency/AgencyComm.cpp +++ b/arangod/Agency/AgencyComm.cpp @@ -23,6 +23,8 @@ //////////////////////////////////////////////////////////////////////////////// #include "AgencyComm.h" +#include "ApplicationFeatures/ApplicationServer.h" +#include "RestServer/ServerFeature.h" #include #ifdef DEBUG_SYNC_REPLICATION @@ -1322,6 +1324,18 @@ AgencyCommResult AgencyComm::sendWithFailover( // timeout exit startegy if (std::chrono::steady_clock::now() < timeOut) { if (tries > 0) { + auto serverFeature = + application_features::ApplicationServer::getFeature( + "Server"); + if (serverFeature->isStopping()) { + LOG_TOPIC(INFO, Logger::AGENCYCOMM) + << "Unsuccessful AgencyComm: Timeout because of shutdown " + << "errorCode: " << result.errorCode() + << " errorMessage: " << result.errorMessage() + << " errorDetails: " << result.errorDetails(); + return result; + } + std::this_thread::sleep_for(waitUntil-std::chrono::steady_clock::now()); if (waitInterval.count() == 0.0) { waitInterval = std::chrono::duration(0.25); diff --git a/arangod/RestServer/ServerFeature.cpp b/arangod/RestServer/ServerFeature.cpp index d601dba8d7..9f932fa412 100644 --- a/arangod/RestServer/ServerFeature.cpp +++ b/arangod/RestServer/ServerFeature.cpp @@ -190,6 +190,7 @@ void ServerFeature::beginShutdown() { std::string msg = ArangoGlobalContext::CONTEXT->binaryName() + " [shutting down]"; TRI_SetProcessTitle(msg.c_str()); + _isStopping = true; } void ServerFeature::waitForHeartbeat() { diff --git a/arangod/RestServer/ServerFeature.h b/arangod/RestServer/ServerFeature.h index 60a121a197..5e4ccf1c6a 100644 --- a/arangod/RestServer/ServerFeature.h +++ b/arangod/RestServer/ServerFeature.h @@ -47,6 +47,7 @@ class ServerFeature final : public application_features::ApplicationFeature { void validateOptions(std::shared_ptr) override final; void start() override final; void beginShutdown() override final; + bool isStopping() const { return _isStopping; } public: OperationMode operationMode() const { return _operationMode; } @@ -70,6 +71,7 @@ class ServerFeature final : public application_features::ApplicationFeature { uint32_t _vppMaxSize; int* _result; OperationMode _operationMode; + bool _isStopping = false; }; } From 7b1c9b7833e6e27cf614e78a6d299dc9cb458502 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Tue, 24 Jan 2017 14:45:09 +0100 Subject: [PATCH 2/2] Instanceinfo and testresult will now be written to the test rootdir --- js/client/modules/@arangodb/testing.js | 23 +++++++++++------------ js/client/tests/agency/agency-test.js | 20 +------------------- js/common/modules/@arangodb/testrunner.js | 6 +++++- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/js/client/modules/@arangodb/testing.js b/js/client/modules/@arangodb/testing.js index e7c2da8188..fecdda3363 100644 --- a/js/client/modules/@arangodb/testing.js +++ b/js/client/modules/@arangodb/testing.js @@ -248,7 +248,7 @@ let LOGS_DIR; let UNITTESTS_DIR; let GDB_OUTPUT=""; -function makeResults (testname) { +function makeResults (testname, instanceInfo) { const startTime = time(); return function (status, message) { @@ -259,7 +259,7 @@ function makeResults (testname) { let result; try { - result = JSON.parse(fs.read('testresult.json')); + result = JSON.parse(fs.read(instanceInfo.rootDir + '/testresult.json')); if ((typeof result[0] === 'object') && result[0].hasOwnProperty('status')) { @@ -691,9 +691,7 @@ function runThere (options, instanceInfo, file) { 'return runTest(' + JSON.stringify(file) + ', true' + mochaGrep + ');'; } - if (options.propagateInstanceInfo) { - testCode = 'global.instanceInfo = ' + JSON.stringify(instanceInfo) + ';\n' + testCode; - } + testCode = 'global.instanceInfo = ' + JSON.stringify(instanceInfo) + ';\n' + testCode; let httpOptions = makeAuthorizationHeaders(options); httpOptions.method = 'POST'; @@ -1078,12 +1076,12 @@ function runInArangosh (options, instanceInfo, file, addArgs) { if (addArgs !== undefined) { args = Object.assign(args, addArgs); } - fs.write('instanceinfo.json', JSON.stringify(instanceInfo)); + require('internal').env.INSTANCEINFO = JSON.stringify(instanceInfo); let rc = executeAndWait(ARANGOSH_BIN, toArgv(args), options); let result; try { - result = JSON.parse(fs.read('testresult.json')); + result = JSON.parse(fs.read(instanceInfo.rootDir + '/testresult.json')); } catch (x) { return rc; } @@ -1116,6 +1114,7 @@ function runArangoshCmd (options, instanceInfo, addArgs, cmds) { args = Object.assign(args, addArgs); } + require('internal').env.INSTANCEINFO = JSON.stringify(instanceInfo); const argv = toArgv(args).concat(cmds); return executeAndWait(ARANGOSH_BIN, argv, options); } @@ -3357,10 +3356,10 @@ testFuncs.recovery = function (options) { // ////////////////////////////////////////////////////////////////////////////// testFuncs.replication_ongoing = function (options) { - const mr = makeResults('replication'); - let master = startInstance('tcp', options, {}, 'master_ongoing'); + const mr = makeResults('replication', master); + if (master === false) { return mr(false, 'failed to start master!'); } @@ -3399,11 +3398,11 @@ testFuncs.replication_ongoing = function (options) { // ////////////////////////////////////////////////////////////////////////////// testFuncs.replication_static = function (options) { - const mr = makeResults('replication'); - let master = startInstance('tcp', options, { 'server.authentication': 'true' }, 'master_static'); + + const mr = makeResults('replication', master); if (master === false) { return mr(false, 'failed to start master!'); @@ -3455,9 +3454,9 @@ testFuncs.replication_static = function (options) { // ////////////////////////////////////////////////////////////////////////////// testFuncs.replication_sync = function (options) { - const mr = makeResults('replication'); let master = startInstance('tcp', options, {}, 'master_sync'); + const mr = makeResults('replication', master); if (master === false) { return mr(false, 'failed to start master!'); } diff --git a/js/client/tests/agency/agency-test.js b/js/client/tests/agency/agency-test.js index cac13a2687..47f092f1f0 100644 --- a/js/client/tests/agency/agency-test.js +++ b/js/client/tests/agency/agency-test.js @@ -56,25 +56,7 @@ function agencyTestSuite () { /// @brief the agency servers //////////////////////////////////////////////////////////////////////////////// - var count = 20; - while (true) { - if (require('fs').exists('instanceinfo.json')) { - var instanceInfoData = require('fs').read('instanceinfo.json'); - var instanceInfo; - try { - instanceInfo = JSON.parse(instanceInfoData); - break; - } catch (err) { - console.error('Failed to parse JSON: instanceinfo.json'); - console.error(instanceInfoData); - } - } - wait(1.0); - if (--count <= 0) { - throw 'peng'; - } - } - + var instanceInfo = JSON.parse(require('internal').env.INSTANCEINFO); var agencyServers = instanceInfo.arangods.map(arangod => { return arangod.url; }); diff --git a/js/common/modules/@arangodb/testrunner.js b/js/common/modules/@arangodb/testrunner.js index 9b605cc55d..9b2935cdbd 100644 --- a/js/common/modules/@arangodb/testrunner.js +++ b/js/common/modules/@arangodb/testrunner.js @@ -10,6 +10,10 @@ var runTest = require('jsunity').runTest, // ////////////////////////////////////////////////////////////////////////////// function runJSUnityTests (tests) { + let instanceinfo = JSON.parse(require('internal').env.INSTANCEINFO); + if (!instanceinfo) { + throw new Error('env.INSTANCEINFO was not set by caller!'); + } var result = true; var allResults = []; var failed = []; @@ -45,7 +49,7 @@ function runJSUnityTests (tests) { internal.wait(0); // force GC }); - require('fs').write('testresult.json', JSON.stringify(allResults)); + require('fs').write(instanceinfo.rootDir + '/testresult.json', JSON.stringify(allResults)); if (failed.length > 1) { print('The following ' + failed.length + ' test files produced errors: ', failed.join(', '));