From e1e0f626470fecd030db868524f9feb32a2bdb38 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 22 Nov 2018 15:29:27 +0100 Subject: [PATCH] add some more intermediate commit tests (#7416) --- ...-collection-rocksdb-failures-noncluster.js | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/js/server/shell/shell-collection-rocksdb-failures-noncluster.js b/tests/js/server/shell/shell-collection-rocksdb-failures-noncluster.js index 2deae9159f..ad8a986ebc 100644 --- a/tests/js/server/shell/shell-collection-rocksdb-failures-noncluster.js +++ b/tests/js/server/shell/shell-collection-rocksdb-failures-noncluster.js @@ -1,5 +1,5 @@ /*jshint globalstrict:false, strict:false */ -/*global assertEqual, assertTrue, assertEqual, assertTypeOf, assertNotEqual, fail, assertFalse */ +/*global assertEqual, assertTrue, assertNull, fail, assertFalse */ //////////////////////////////////////////////////////////////////////////////// /// @brief test the collection interface @@ -294,12 +294,102 @@ function CollectionTruncateFailuresSuite() { }; } +function IntermediateCommitFailureSuite() { + 'use strict'; + const cn = "UnitTestsIntermediate"; + let c; + const cleanUp = () => { + internal.debugClearFailAt(); + try { + db._drop(cn); + } catch(_) { } + }; + + const docs = []; + for (let i = 0; i < 10000; ++i) { + docs.push({value: i % 250, value2: i % 100}); + } + + return { + + tearDown: cleanUp, + + setUp: function () { + cleanUp(); + c = db._create(cn); + c.insert(docs); + }, + + testFailOnRemoveAql: function () { + internal.debugSetFailAt("FailBeforeIntermediateCommit"); + try { + db._query("FOR doc IN @@cn REMOVE doc IN @@cn", { "@cn" : cn }, { intermediateCommitCount: 10000 }); + fail(); + } catch (e) { + // Validate that we died with debug + assertEqual(e.errorNum, ERRORS.ERROR_DEBUG.code); + } + + assertEqual(c.count(), 10000); + assertEqual(c.toArray().length, 10000); + }, + + testFailOnUpdateAql: function () { + internal.debugSetFailAt("FailBeforeIntermediateCommit"); + try { + db._query("FOR doc IN @@cn UPDATE doc WITH { aha: 1 } IN @@cn", { "@cn" : cn }, { intermediateCommitCount: 10000 }); + fail(); + } catch (e) { + // Validate that we died with debug + assertEqual(e.errorNum, ERRORS.ERROR_DEBUG.code); + } + + assertEqual(c.count(), 10000); + assertEqual(c.toArray().length, 10000); + + assertNull(c.firstExample({ aha: 1 })); + }, + + testFailOnReplaceAql: function () { + internal.debugSetFailAt("FailBeforeIntermediateCommit"); + try { + db._query("FOR doc IN @@cn REPLACE doc WITH { aha: 1 } IN @@cn", { "@cn" : cn }, { intermediateCommitCount: 10000 }); + fail(); + } catch (e) { + // Validate that we died with debug + assertEqual(e.errorNum, ERRORS.ERROR_DEBUG.code); + } + + assertEqual(c.count(), 10000); + assertEqual(c.toArray().length, 10000); + + assertNull(c.firstExample({ aha: 1 })); + }, + + testFailOnInsertAql: function () { + internal.debugSetFailAt("FailBeforeIntermediateCommit"); + try { + db._query("FOR i IN 1..10000 INSERT {} IN @@cn", { "@cn" : cn }, { intermediateCommitCount: 10000 }); + fail(); + } catch (e) { + // Validate that we died with debug + assertEqual(e.errorNum, ERRORS.ERROR_DEBUG.code); + } + + assertEqual(c.count(), 10000); + assertEqual(c.toArray().length, 10000); + }, + + }; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief executes the test suites //////////////////////////////////////////////////////////////////////////////// if (internal.debugCanUseFailAt()) { jsunity.run(CollectionTruncateFailuresSuite); + jsunity.run(IntermediateCommitFailureSuite); } return jsunity.done();