1
0
Fork 0

Add forgotten greylisted files

This commit is contained in:
KVS85 2019-04-30 22:18:48 +02:00
parent 893a1fb63c
commit 5406cb7447
2 changed files with 378 additions and 0 deletions

View File

@ -0,0 +1,265 @@
/*jshint strict: false, sub: true */
/*global arango, assertTrue, assertNotNull, assertNotUndefined, assertNotEqual */
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2014 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Andreas Streichardt
////////////////////////////////////////////////////////////////////////////////
const jsunity = require('jsunity');
const arangodb = require('@arangodb');
const wait = require('internal').wait;
const db = arangodb.db;
const internal = require('internal');
const request = require('@arangodb/request');
const foxxManager = require('@arangodb/foxx/manager');
const suspendExternal = internal.suspendExternal;
const continueExternal = internal.continueExternal;
const download = internal.download;
const pathForTesting = require('internal').pathForTesting;
const instanceInfo = JSON.parse(internal.env.INSTANCEINFO);
try {
let globals = JSON.parse(process.env.ARANGOSH_GLOBALS);
Object.keys(globals).forEach(g => {
global[g] = globals[g];
});
} catch (e) {
}
let executeOnServer = function(code) {
let httpOptions = {};
httpOptions.method = 'POST';
httpOptions.timeout = 3600;
httpOptions.returnBodyOnError = true;
const reply = download(instanceInfo.url + '/_admin/execute?returnAsJSON=true',
code,
httpOptions);
if (!reply.error && reply.code === 200) {
return JSON.parse(reply.body);
} else {
throw new Error('Could not send to server ' + JSON.stringify(reply));
}
};
function serverSetup() {
let directory = require('./' + pathForTesting('client/assets/queuetest/dirname.js'));
db._create('foxxqueuetest', {numberOfShards: 1, replicationFactor: 1});
db.foxxqueuetest.insert({'_key': 'test', 'date': null, 'server': null});
foxxManager.install(directory, '/queuetest');
const serverCode = `
const queues = require('@arangodb/foxx/queues');
let queue = queues.create('q');
queue.push({mount: '/queuetest', name: 'queuetest', 'repeatTimes': -1, 'repeatDelay': 1000}, {});
`;
executeOnServer(serverCode);
}
function serverTeardown() {
const serverCode = `
const queues = require('@arangodb/foxx/queues');
queues.delete('q');
`;
executeOnServer(serverCode);
foxxManager.uninstall('/queuetest');
db._drop('foxxqueuetest');
}
function responseIsSuccess(res) {
return res !== undefined && res.hasOwnProperty('status')
&& 200 <= res.status && res.status < 300;
}
function sendCanFailAtTo(endpoint) {
const url = endpoint.replace(/^tcp:/, 'http:')
+ "/_admin/debug/failat";
const res = request({method: 'GET', url: url});
return responseIsSuccess(res);
}
function sendSetFailAtTo(endpoint, failurePoint) {
const url = endpoint.replace(/^tcp:/, 'http:')
+ "/_admin/debug/failat/"
+ encodeURIComponent(failurePoint);
const res = request({method: 'PUT', url: url});
return responseIsSuccess(res);
}
function sendRemoveFailAtTo(endpoint, failurePoint) {
const url = endpoint.replace(/^tcp:/, 'http:')
+ "/_admin/debug/failat/"
+ encodeURIComponent(failurePoint);
const res = request({method: 'DELETE', url: url});
return responseIsSuccess(res);
}
function FoxxmasterSuite() {
return {
setUpAll: function() {
serverSetup();
let document = db._collection('foxxqueuetest').document('test');
let count = 0;
// Even a minute could be not enough to start a Foxx service in a queue
while (document.server == null && count++ < 12) {
wait(10);
document = db._collection('foxxqueuetest').document('test');
}
},
tearDownAll : function () {
serverTeardown();
},
testQueueWorks: function() {
let document = db._collection('foxxqueuetest').document('test');
assertNotNull(document.server);
wait(2);
assertNotEqual(document.date, db._collection('foxxqueuetest').document('test').date);
},
testQueueFailover: function() {
let document = db._collection('foxxqueuetest').document('test');
let server = document.server;
assertNotNull(server);
let instance = instanceInfo.arangods.filter(arangod => {
if (arangod.role === 'agent') {
return false;
}
let url = arangod.endpoint.replace(/tcp/, 'http') + '/_admin/server/id';
let res = request({method: 'GET', url: url});
let parsed = JSON.parse(res.body);
if (parsed.id === server) {
assertTrue(suspendExternal(arangod.pid));
}
return parsed.id === server;
})[0];
assertNotUndefined(instance);
assertTrue(suspendExternal(instance.pid));
let newEndpoint = instanceInfo.arangods.filter(arangod => {
return arangod.role === 'coordinator' && arangod.pid !== instance.pid;
})[0];
arango.reconnect(newEndpoint.endpoint, db._name(), 'root', '');
let waitInterval = 1;
let waited = 0;
let ok = false;
while (waited <= 30) {
document = db._collection('foxxqueuetest').document('test');
let newServer = document.server;
if (server !== newServer) {
ok = true;
break;
}
wait(waitInterval);
waited += waitInterval;
}
assertTrue(continueExternal(instance.pid));
// mop: currently supervision would run every 5s
// vadim: but that is not guaranteed that a Foxx service will be srarted right after that, so the timeout of expected 'newServer' was raised to 30s
if (!ok) {
throw new Error('Supervision should have moved the Foxx queues and Foxx queues should have been started to run on a new coordinator');
}
},
testQueueFailoverDuringJob: function() {
let document = db._collection('foxxqueuetest').document('test');
let server = document.server;
assertNotNull(server);
let instance = instanceInfo.arangods.filter(arangod => {
if (arangod.role === 'agent') {
return false;
}
let url = arangod.endpoint.replace(/tcp/, 'http') + '/_admin/server/id';
let res = request({method: 'GET', url: url});
let parsed = JSON.parse(res.body);
return parsed.id === server;
})[0];
assertNotUndefined(instance);
if (!sendCanFailAtTo(instance.endpoint)) {
console.info("Failure tests disabled, skipping...");
return;
}
// The process should now suspend while the next job is in progress
assertTrue(
sendSetFailAtTo(instance.endpoint, "foxxmaster::queuetest")
);
let newEndpoint = instanceInfo.arangods.filter(arangod => {
return arangod.role === 'coordinator' && arangod.pid !== instance.pid;
})[0];
arango.reconnect(newEndpoint.endpoint, db._name(), 'root', '');
let waitInterval = 1;
let waited = 0;
let ok = false;
while (waited <= 30) {
document = db._collection('foxxqueuetest').document('test');
let newServer = document.server;
if (server !== newServer) {
ok = true;
break;
}
wait(waitInterval);
waited += waitInterval;
}
// Continue the process and remove the failure point
assertTrue(continueExternal(instance.pid));
assertTrue(
sendRemoveFailAtTo(instance.endpoint, "foxxmaster::queuetest")
);
// mop: currently supervision would run every 5s
// vadim: but that is not guaranteed that a Foxx service will be srarted right after that, so the timeout of expected 'newServer' was raised to 30s
if (!ok) {
throw new Error('Supervision should have moved the Foxx queues and Foxx queues should have been started to run on a new coordinator');
}
}
};
}
////////////////////////////////////////////////////////////////////////////////
/// @brief executes the test suite
////////////////////////////////////////////////////////////////////////////////
jsunity.run(FoxxmasterSuite);
return jsunity.done();

View File

@ -0,0 +1,113 @@
/* jshint globalstrict:false, strict:false, unused : false */
/* global assertEqual, assertTrue, assertFalse, assertNull, fail, AQL_EXECUTE */
// //////////////////////////////////////////////////////////////////////////////
// / @brief recovery tests for views
// /
// / @file
// /
// / DISCLAIMER
// /
// / Copyright 2010-2012 triagens GmbH, Cologne, Germany
// /
// / Licensed under the Apache License, Version 2.0 (the "License")
// / you may not use this file except in compliance with the License.
// / You may obtain a copy of the License at
// /
// / http://www.apache.org/licenses/LICENSE-2.0
// /
// / Unless required by applicable law or agreed to in writing, software
// / distributed under the License is distributed on an "AS IS" BASIS,
// / WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// / See the License for the specific language governing permissions and
// / limitations under the License.
// /
// / Copyright holder is triAGENS GmbH, Cologne, Germany
// /
// / @author Jan Steemann
// / @author Copyright 2013, triAGENS GmbH, Cologne, Germany
// //////////////////////////////////////////////////////////////////////////////
var db = require('@arangodb').db;
var internal = require('internal');
var jsunity = require('jsunity');
function runSetup () {
'use strict';
internal.debugClearFailAt();
db._drop('UnitTestsRecoveryDummy');
var c = db._create('UnitTestsRecoveryDummy');
db._dropView('UnitTestsRecoveryView');
db._createView('UnitTestsRecoveryView', 'arangosearch', {});
var meta = { links: { 'UnitTestsRecoveryDummy': { includeAllFields: true } } };
db._view('UnitTestsRecoveryView').properties(meta);
internal.wal.flush(true, true);
internal.debugSetFailAt("FlushThreadDisableAll");
internal.wait(2); // make sure failure point takes effect
var tx = {
collections: {
write: ['UnitTestsRecoveryDummy']
},
action: function() {
var c = db.UnitTestsRecoveryDummy;
for (let i = 0; i < 10000; i++) {
c.save({ a: "foo_" + i, b: "bar_" + i, c: i });
}
},
waitForSync: true
};
db._executeTransaction(tx);
internal.debugSegfault('crashing server');
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief test suite
// //////////////////////////////////////////////////////////////////////////////
function recoverySuite () {
'use strict';
jsunity.jsUnity.attachAssertions();
return {
setUp: function () {},
tearDown: function () {},
// //////////////////////////////////////////////////////////////////////////////
// / @brief test whether we can restore the trx data
// //////////////////////////////////////////////////////////////////////////////
testIResearchLinkPopulateTransactionNoFlushThread: function () {
var v = db._view('UnitTestsRecoveryView');
assertEqual(v.name(), 'UnitTestsRecoveryView');
assertEqual(v.type(), 'arangosearch');
var p = v.properties().links;
assertTrue(p.hasOwnProperty('UnitTestsRecoveryDummy'));
assertTrue(p.UnitTestsRecoveryDummy.includeAllFields);
var result = AQL_EXECUTE("FOR doc IN UnitTestsRecoveryView SEARCH doc.c >= 0 OPTIONS {waitForSync: true} COLLECT WITH COUNT INTO length RETURN length").json;
assertEqual(result[0], 10000);
}
};
}
// //////////////////////////////////////////////////////////////////////////////
// / @brief executes the test suite
// //////////////////////////////////////////////////////////////////////////////
function main (argv) {
'use strict';
if (argv[1] === 'setup') {
runSetup();
return 0;
} else {
jsunity.run(recoverySuite);
return jsunity.writeDone().status ? 0 : 1;
}
}