Skip to content

Commit

Permalink
Stabilize Hybrid Smart Graph Test [EE only] (#14809)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchacki committed Sep 22, 2021
1 parent 4e555c6 commit e6589a6
Showing 1 changed file with 50 additions and 1 deletion.
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;
};

0 comments on commit e6589a6

Please sign in to comment.