Skip to content
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

Stabilize Hybrid Smart Graph Test [EE only] #14809

Merged
Merged
Changes from all commits
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
51 changes: 50 additions & 1 deletion js/server/modules/@arangodb/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jshint strict: false */
/*global arango, db */
/*global arango, db, assertTrue */

// //////////////////////////////////////////////////////////////////////////////
// / @brief Helper for JavaScript Tests
Expand Down Expand Up @@ -42,6 +42,7 @@ let {
isEqual,
compareStringIds,
} = require('@arangodb/test-helper-common');
const clusterInfo = global.ArangoClusterInfo;

exports.getServerById = getServerById;
exports.getServersByType = getServersByType;
Expand Down Expand Up @@ -122,3 +123,51 @@ exports.getMetric = function (endpoint, name) {
}
return Number(matches[0].replace(/^.* (\d+)$/, '$1'));
};

exports.waitForShardsInSync = function(cn, timeout) {
if (!timeout) {
timeout = 300;
}
// The client variant has the database name inside it's scope.
// TODO: Need to figure out how to get that done on server api. As soon as
// this is necessary. We can always hand it in as parameter, but then we have
// differences for client / server on this helper methods api ;(
let dbName = "_system";
let start = internal.time();
const setsAreEqual = (left, right) => {
// Sets have to be equal in size
if (left.size !== right.size) {
return false;
}
// Every entry in left, needs to be in right.
// THere can be no duplicates in a set, so this
// is equivalent to left and right having exactly the
// same entries.
for (const entry of left) {
if (!right.has(entry)) {
return false;
}
}
return true;
};

while (internal.time() - start < timeout) {
let insync = 0;
const { shards } = clusterInfo.getCollectionInfo(dbName, cn);
for (const [shard, plannedServers] of Object.entries(shards)) {
const { servers } = clusterInfo.getCollectionInfoCurrent(dbName, cn, shard);
if (setsAreEqual(new Set(servers), new Set(plannedServers))) {
++insync;
}
}
if (insync === Object.keys(shards).length) {
return;
}
if ((internal.time() - start) * 2 > timeout) {
console.warn(`Only ${insync} in-sync out of ${Object.keys(shards).length} after ${internal.time() - start}, waiting until ${timeout}`);
}
internal.wait(1);
}
assertTrue(false, "Shards were not getting in sync in time, giving up!");
return;
};