8000 Bug fix/fix active failover foxx failover by dothebart · Pull Request #14754 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/fix active failover foxx failover #14754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add failover foxx test
  • Loading branch information
dothebart committed Sep 10, 2021
commit 26a2aadd7e25c0fa433054b4b5eb8a7c27a6261d
142 changes: 139 additions & 3 deletions tests/js/client/active-failover/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ const request = require("@arangodb/request");
const tasks = require("@arangodb/tasks");

const arango = internal.arango;
const compareTicks = require("@arangodb/replication").compareTicks;
const wait = internal.wait;
const db = internal.db;
const fs = require('fs');
const path = require('path');
const utils = require('@arangodb/foxx/manager-utils');
const wait = internal.wait;

const compareTicks = require("@arangodb/replication").compareTicks;
const suspendExternal = internal.suspendExternal;
const continueExternal = internal.continueExternal;

Expand Down Expand Up @@ -293,10 +296,136 @@ function waitUntilHealthStatusIs(isHealthy, isFailed) {
return false;
}

function loadFoxxIntoZip(path) {
let zip = utils.zipDirectory(path);
let content = fs.readFileSync(zip);
fs.remove(zip);
return {
type: 'inlinezip',
buffer: content
};
}
function checkFoxxService() {
const onlyJson = {
'accept': 'application/json',
'accept-content-type': 'application/json'
};
let reply;
db._useDatabase("_system");

[
'/_db/_system/_admin/aardvark/index.html',
'/_db/_system/itz/index'
//, '/_db/_system/crud/xxx'
].forEach(route => {
for (let i=0; i < 200; i++) {
try {
reply = arango.GET_RAW(route, onlyJson);
if (reply.code === 200) {
print(route + " OK");
return;
}
let msg = JSON.stringify(reply);
if (reply.hasOwnProperty('parsedBody')) {
msg = " '" + reply.parsedBody.errorNum + "' - " + reply.parsedBody.errorMessage;
}
print(route + " Not yet ready, retrying: " + msg);
} catch (e) {
print(route + " Caught - need to retry. " + JSON.stringify(e));
}
internal.sleep(3);
}
throw ("foxx route '" + route + "' not ready on time!");
});

print("Foxx: Itzpapalotl getting the root of the gods");
reply = arango.GET_RAW('/_db/_system/itz');
assertEqual(reply.code, "307", JSON.stringify(reply));

print('Foxx: Itzpapalotl getting index html with list of gods');
reply = arango.GET_RAW('/_db/_system/itz/index');
assertEqual(reply.code, "200", JSON.stringify(reply));

print("Foxx: Itzpapalotl summoning Chalchihuitlicue");
reply = arango.GET_RAW('/_db/_system/itz/Chalchihuitlicue/summon', onlyJson);
assertEqual(reply.code, "200", JSON.stringify(reply));
let parsedBody = JSON.parse(reply.body);
assertEqual(parsedBody.name, "Chalchihuitlicue");
assertTrue(parsedBody.summoned);

//print("Foxx: crud testing get xxx");
//reply = arango.GET_RAW('/_db/_system/crud/xxx', onlyJson);
//assertEqual(reply.code, "200");
//parsedBody = JSON.parse(reply.body);
//assertEqual(parsedBody, []);
//
//print("Foxx: crud testing POST xxx");
//
//reply = arango.POST_RAW('/_db/_system/crud/xxx', {_key: "test"})
//if (options.readOnly) {
// assertEqual(reply.code, "400");
//} else {
// assertEqual(reply.code, "201");
//}
//
//print("Foxx: crud testing get xxx");
//reply = arango.GET_RAW('/_db/_system/crud/xxx', onlyJson);
//assertEqual(reply.code, "200");
//parsedBody = JSON.parse(reply.body);
//if (options.readOnly) {
// assertEqual(parsedBody, []);
//} else {
// assertEqual(parsedBody.length, 1);
//}
//
//print('Foxx: crud testing delete document')
//reply = arango.DELETE_RAW('/_db/_system/crud/xxx/' + 'test');
//if (options.readOnly) {
// assertEqual(reply.code, "400");
//} else {
// assertEqual(reply.code, "204");
//}
}

function installFoxx(mountpoint, which, mode) {
let headers = {};
let content;
if (which.type === 'js') {
headers['content-type'] = 'application/javascript';
content = which.buffer;
} else if (which.type === 'dir') {
headers['content-type'] = 'application/zip';
var utils = require('@arangodb/foxx/manager-utils');
let zip = utils.zipDirectory(which.buffer);
content = fs.readFileSync(zip);
fs.remove(zip);
} else if (which.type === 'inlinezip') {
content = which.buffer;
headers['content-type'] = 'application/zip';
} else if (which.type === 'url') {
content = { source: which };
} else if (which.type === 'file') {
content = fs.readFileSync(which.buffer);
}
let devmode = '';
if (typeof which.devmode === "boolean") {
devmode = `&development=${which.devmode}`;
}
let crudResp;
if (mode === "upgrade") {
crudResp = arango.PATCH('/_api/foxx/service?mount=' + mountpoint + devmode, content, headers);
} else if (mode === "replace") {
crudResp = arango.PUT('/_api/foxx/service?mount=' + mountpoint + devmode, content, headers);
} else {
crudResp = arango.POST('/_api/foxx?mount=' + mountpoint + devmode, content, headers);
}
expect(crudResp).to.have.property('manifest');
return crudResp;
}

// Testsuite that quickly checks some of the basic premises of
// the active failover functionality. It is designed as a quicker
// variant of the node resilience tests (for active failover).
// Things like Foxx resilience are not tested
function ActiveFailoverSuite() {
let servers = getClusterEndpoints();
assertTrue(servers.length >= 4, "This test expects four single instances");
Expand Down Expand Up @@ -370,7 +499,11 @@ function ActiveFailoverSuite() {
// Simple failover case: Leader is suspended, slave needs to
// take over within a reasonable amount of time
testFailover: function () {
const itzpapalotlPath = path.resolve(internal.pathForTesting('common'), 'test-data', 'apps', 'itzpapalotl');
const itzpapalotlZip = loadFoxxIntoZip(itzpapalotlPath);

installFoxx("/itz", itzpapalotlZip);
checkFoxxService();
assertTrue(checkInSync(currentLead, servers));
assertEqual(checkData(currentLead), 10000);

Expand All @@ -393,6 +526,9 @@ function ActiveFailoverSuite() {
// check the remaining followers get in sync
assertTrue(checkInSync(currentLead, servers, oldLead));

connectToServer(currentLead);
checkFoxxService();

// restart the old leader
suspended.forEach(arangod => {
print("Resuming: ", arangod.endpoint);
Expand Down
0