Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const waitForTasks = () => {
const time = require("internal").time;
const start = time();
while (!tasksCompleted()) {
if (time() - start > 300) { // wait for 5 minutes maximum
fail("Timeout after 5 minutes");
}
require("internal").wait(0.5, false);
}
require('internal').wal.flush(true, true);
// wait an extra second for good measure
require("internal").wait(1.0, false);
};
const waitForTasks = () => {
const time = require("internal").time;
const start = time();
while (!tasksCompleted()) {
if (time() - start > 300) { // wait for 5 minutes maximum
fail("Timeout after 5 minutes");
}
require("internal").wait(0.5, false);
}
require('internal').wal.flush(true, true);
// wait an extra second for good measure
require("internal").wait(1.0, false);
};
db._drop('UnitTestsRecovery');
var c = db._create('UnitTestsRecovery'), i, fig;
for (i = 0; i < 1000; ++i) {
c.save({ _key: 'test' + i, value1: 'test' + i, value2: i });
}
internal.wal.flush(true, true);
// wait until journal appears
while (true) {
fig = c.figures();
if (fig.journals.count > 0) {
break;
}
internal.wait(1, false);
}
c.rotate();
for (i = 1000; i < 2000; ++i) {
c.save({ _key: 'test' + i, value1: 'test' + i, value2: i });
}
internal.wal.flush(true, true);
// wait until next journal appears
while (true) {
fig = c.figures();
if (fig.journals.count > 0) {
break;
}
internal.wait(1, false);
db._drop('UnitTestsRecovery');
var c = db._create('UnitTestsRecovery'), i, fig;
for (i = 0; i < 1000; ++i) {
c.save({ _key: 'test' + i, value1: 'test' + i, value2: i });
}
internal.wal.flush(true, true);
// wait until journal appears
while (true) {
fig = c.figures();
if (fig.journals.count > 0) {
break;
}
internal.wait(1, false);
}
internal.debugSetFailAt('CreateMultipleJournals');
c.rotate();
for (i = 200; i < 400; ++i) {
c.remove('test' + i);
}
for (i = 500; i < 700; ++i) {
c.update('test' + i, { value2: 'test' + i });
}
internal.wal.flush(true, true);
// wait until next journal appears
action: function () {
require("internal").wait(7, false);
var db = require("internal").db;
db.UnitTestsDeadlock2.any();
db.UnitTestsDeadlock1.insert({ done: true });
}
});