8000 Feature/start sut only once if needed (#10805) · waveray/arangodb@4d59726 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d59726

Browse files
dothebartmarkuspf
authored andcommitted
Feature/start sut only once if needed (arangodb#10805)
* Work on resetDeadJobs * Document properly what the function is indended to do * Leave the retry loop if shutting down * Simplify and refactor * re-start SUT only if the test requires it to save resources * move tests to other suite * fix typos Co-authored-by: Markus Pfeiffer <markuspf@users.noreply.github.com>
1 parent 1fe4397 commit 4d59726

17 files changed

+128
-81
lines changed

js/client/modules/@arangodb/process-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function makeAuthorizationHeaders (options) {
441441
{'server_id': 'none',
442442
'iss': 'arangodb'}, 'HS256');
443443
if (options.extremeVerbosity) {
444-
print(Date() + ' Using jwt token: ' + jwt);
444+
print(Date() + ' Using jw token: ' + jwt);
445445
}
446446
return {
447447
'headers': {

js/client/modules/@arangodb/testsuites/server_permissions.js

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,69 +47,81 @@ const RESET = require('internal').COLORS.COLOR_RESET;
4747
// const YELLOW = require('internal').COLORS.COLOR_YELLOW;
4848

4949
const functionsDocumentation = {
50-
'server_permissions': 'permissions test for the server'
50+
'server_permissions': 'permissions test for the server',
51+
'server_parameters': 'specifies startup parameters for the instance'
5152
};
5253

5354
const testPaths = {
54-
'server_permissions': [tu.pathForTesting('client/server_permissions')]
55+
'server_permissions': [tu.pathForTesting('client/server_permissions')],
56+
'server_parameters': [tu.pathForTesting('client/server_parameters')]
5557
};
5658

57-
function server_permissions(options) {
59+
function startParameterTest(options, testpath, suiteName) {
5860
let count = 0;
5961
let results = { shutdown: true };
6062
let filtered = {};
61-
const tests = tu.scanTestPaths(testPaths.server_permissions, options);
63+
const tests = tu.scanTestPaths(testpath, options);
6264

6365
tests.forEach(function (testFile, i) {
6466
count += 1;
6567
if (tu.filterTestcaseByOptions(testFile, options, filtered)) {
6668
// pass on JWT secret
69+
let instanceInfo;
70+
let shutdownStatus;
6771
let clonedOpts = _.clone(options);
72+
let paramsFirstRun = {};
6873
let serverOptions = {};
69-
if (serverOptions['server.jwt-secret'] && !clonedOpts['server.jwt-secret']) {
70-
clonedOpts['server.jwt-secret'] = serverOptions['server.jwt-secret'];
71-
}
7274

73-
let paramsFistRun = {};
74-
let paramsSecondRun;
75-
let rootDir = fs.join(fs.getTempPath(), count.toString());
76-
let instanceInfo = pu.startInstance(options.protocol, options, paramsFistRun, "server_permissions", rootDir); // fist start
77-
pu.cleanupDBDirectoriesAppend(instanceInfo.rootDir);
78-
try {
79-
print(BLUE + '================================================================================' + RESET);
80-
print(CYAN + 'Running Setup of: ' + testFile + RESET);
81-
let content = fs.read(testFile);
82-
content = `(function(){ const getOptions = true; ${content}
75+
let fileContent = fs.read(testFile);
76+
let content = `(function(){ const runSetup = false; const getOptions = true; ${fileContent}
8377
}())`; // DO NOT JOIN WITH THE LINE ABOVE -- because of content could contain '//' at the very EOF
8478

85-
paramsSecondRun = executeScript(content, true, testFile);
86-
} catch (ex) {
87-
let shutdownStatus = pu.shutdownInstance(instanceInfo, clonedOpts, false); // stop
88-
results[testFile] = {
89-
status: false,
90-
messages: 'Warmup of system failed: ' + ex,
91-
shutdown: shutdownStatus
92-
};
93-
results['shutdown'] = results['shutdown'] && shutdownStatus;
94-
return;
95-
}
96-
79+
let paramsSecondRun = executeScript(content, true, testFile);
80+
let rootDir = fs.join(fs.getTempPath(), count.toString());
81+
let runSetup = paramsSecondRun.hasOwnProperty('runSetup');
9782
if (paramsSecondRun.hasOwnProperty('server.jwt-secret')) {
9883
clonedOpts['server.jwt-secret'] = paramsSecondRun['server.jwt-secret'];
9984
}
100-
let shutdownStatus = pu.shutdownInstance(instanceInfo, clonedOpts, false); // stop
101-
if (shutdownStatus) {
102-
pu.reStartInstance(clonedOpts, instanceInfo, paramsSecondRun); // restart with restricted permissions
103-
results[testFile] = tu.runInLocalArangosh(options, instanceInfo, testFile, {});
104-
shutdownStatus = pu.shutdownInstance(instanceInfo, clonedOpts, false);
105-
}
106-
else {
107-
results[testFile] = {
108-
status: false,
109-
message: "failed to stop instance",
110-
shutdown: false
111-
};
85+
if (runSetup) {
86+
delete paramsSecondRun.runSetup;
87+
instanceInfo = pu.startInstance(options.protocol, options, paramsFirstRun, suiteName, rootDir); // first start
88+
pu.cleanupDBDirectoriesAppend(instanceInfo.rootDir);
89+
try {
90+
print(BLUE + '================================================================================' + RESET);
91+
print(CYAN + 'Running Setup of: ' + testFile + RESET);
92+
content = `(function(){ const runSetup = true; const getOptions = false; ${fileContent}
93+
}())`; // DO NOT JOIN WITH THE LINE ABOVE -- because of content could contain '//' at the very EOF
94+
95+
if (!executeScript(content, true, testFile)) {
96+
throw new Error("setup of test failed");
97+
}
98+
} catch (ex) {
99+
shutdownStatus = pu.shutdownInstance(instanceInfo, clonedOpts, false); // stop
100+
results[testFile] = {
101+
status: false,
102+
messages: 'Warmup of system failed: ' + ex,
103+
shutdown: shutdownStatus
104+
};
105+
results['shutdown'] = results['shutdown'] && shutdownStatus;
106+
return;
107+
}
108 F438 +
if (pu.shutdownInstance(instanceInfo, clonedOpts, false)) { // stop
109+
pu.reStartInstance(clonedOpts, instanceInfo, paramsSecondRun); // restart with restricted permissions
110+
}
111+
else {
112+
results[testFile] = {
113+
status: false,
114+
message: "failed to stop instance",
115+
shutdown: false
116+
};
117+
}
118+
} else {
119+
instanceInfo = pu.startInstance(options.protocol, options, paramsSecondRun, suiteName, rootDir); // one start
112120
}
121+
122+
results[testFile] = tu.runInLocalArangosh(options, instanceInfo, testFile, {});
123+
shutdownStatus = pu.shutdownInstance(instanceInfo, clonedOpts, false);
124+
113125
results['shutdown'] = results['shutdown'] && shutdownStatus;
114126

115127
if (!results[testFile].status || !shutdownStatus) {
@@ -128,8 +140,17 @@ function server_permissions(options) {
128140
return results;
129141
}
130142

143+
function server_permissions(options) {
144+
return startParameterTest(options, testPaths.server_permissions, "server_permissions");
145+
}
146+
147+
function server_parameters(options) {
148+
return startParameterTest(options, testPaths.server_parameters, "server_parameters");
149+
}
150+
131151
exports.setup = function (testFns, defaultFns, opts, fnDocs, optionsDoc, allTestPaths) {
132152
Object.assign(allTestPaths, testPaths);
133153
testFns['server_permissions'] = server_permissions;
154+
testFns['server_parameters'] = server_parameters;
134155
for (var attrname in functionsDocumentation) { fnDocs[attrname] = functionsDocumentation[attrname]; }
135156
};

js/common/modules/jsunity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ function RunTest (path, outputReply, filter) {
378378

379379
content = fs.read(path);
380380

381-
content = `(function(){ require('jsunity').jsUnity.attachAssertions(); return (function() { require('jsunity').setTestFilter(${JSON.stringify(filter)}); const getOptions = false; ${content} }());
381+
content = `(function(){ require('jsunity').jsUnity.attachAssertions(); return (function() { require('jsunity').setTestFilter(${JSON.stringify(filter)}); const runSetup = false; const getOptions = false; ${content} }());
382382
});`;
383383
f = internal.executeScript(content, undefined, path);
384384

0 commit comments

Comments
 (0)
0