diff options
author | Spencer T Brody <spencer@mongodb.com> | 2018-06-04 18:35:29 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2018-06-05 18:10:59 -0400 |
commit | b98ee66f2867a0a65dcaba1d784ad19caed76a3e (patch) | |
tree | 9156ffa58a3cdb7f5ab1abb3a38ed729da3acf72 /jstests | |
parent | 975569e47b84dd70c20e81b2abb6b991195c8391 (diff) | |
download | mongo-b98ee66f2867a0a65dcaba1d784ad19caed76a3e.tar.gz |
SERVER-35397 Add logging to do_txn_basic.js test
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/txns/do_txn_basic.js | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/jstests/core/txns/do_txn_basic.js b/jstests/core/txns/do_txn_basic.js index 72d69e77bde..7e9bd4b98e1 100644 --- a/jstests/core/txns/do_txn_basic.js +++ b/jstests/core/txns/do_txn_basic.js @@ -17,25 +17,25 @@ // Input validation tests // - // Empty array of operations. + jsTestLog("Empty array of operations."); assert.commandFailedWithCode(db.adminCommand({doTxn: [], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.InvalidOptions, 'doTxn should fail on empty array of operations'); - // Non-array type for operations. + jsTestLog("Non-array type for operations."); assert.commandFailedWithCode( db.adminCommand({doTxn: "not an array", txnNumber: NumberLong(txnNumber++)}), ErrorCodes.TypeMismatch, 'doTxn should fail on non-array type for operations'); - // Missing 'op' field in an operation. + jsTestLog("Missing 'op' field in an operation."); assert.commandFailedWithCode( db.adminCommand( {doTxn: [{ns: t.getFullName(), o: {_id: 0}}], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.FailedToParse, 'doTxn should fail on operation without "op" field'); - // Non-string 'op' field in an operation. + jsTestLog("Non-string 'op' field in an operation."); assert.commandFailedWithCode(db.adminCommand({ doTxn: [{op: 12345, ns: t.getFullName(), o: {_id: 0}}], txnNumber: NumberLong(txnNumber++) @@ -43,7 +43,7 @@ ErrorCodes.FailedToParse, 'doTxn should fail on operation with non-string "op" field'); - // Empty 'op' field value in an operation. + jsTestLog("Empty 'op' field value in an operation."); assert.commandFailedWithCode(db.adminCommand({ doTxn: [{op: '', ns: t.getFullName(), o: {_id: 0}}], txnNumber: NumberLong(txnNumber++) @@ -51,46 +51,46 @@ ErrorCodes.FailedToParse, 'doTxn should fail on operation with empty "op" field value'); - // Missing 'ns' field in an operation. + jsTestLog("Missing 'ns' field in an operation."); assert.commandFailedWithCode( db.adminCommand({doTxn: [{op: 'u', o: {_id: 0}}], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.FailedToParse, 'doTxn should fail on operation without "ns" field'); - // Missing 'o' field in an operation. + jsTestLog("Missing 'o' field in an operation."); assert.commandFailedWithCode( db.adminCommand( {doTxn: [{op: 'u', ns: t.getFullName()}], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.FailedToParse, 'doTxn should fail on operation without "o" field'); - // Non-string 'ns' field in an operation. + jsTestLog("Non-string 'ns' field in an operation."); assert.commandFailedWithCode( db.adminCommand( {doTxn: [{op: 'u', ns: 12345, o: {_id: 0}}], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.FailedToParse, 'doTxn should fail on operation with non-string "ns" field'); - // Missing dbname in 'ns' field. + jsTestLog("Missing dbname in 'ns' field."); assert.commandFailedWithCode( db.adminCommand( {doTxn: [{op: 'd', ns: t.getName(), o: {_id: 1}}], txnNumber: NumberLong(txnNumber++)}), ErrorCodes.InvalidNamespace, 'doTxn should fail with a missing dbname in the "ns" field value'); - // Empty 'ns' field value. + jsTestLog("Empty 'ns' field value."); assert.commandFailed( db.adminCommand( {doTxn: [{op: 'u', ns: '', o: {_id: 0}}], txnNumber: NumberLong(txnNumber++)}), 'doTxn should fail with empty "ns" field value'); - // Valid 'ns' field value in unknown operation type 'x'. + jsTestLog("Valid 'ns' field value in unknown operation type 'x'."); assert.commandFailedWithCode( db.adminCommand({doTxn: [{op: 'x', ns: t.getFullName(), o: {_id: 0}}]}), ErrorCodes.FailedToParse, 'doTxn should fail on unknown operation type "x" with valid "ns" value'); - // Illegal operation type 'n' (no-op). + jsTestLog("Illegal operation type 'n' (no-op)."); assert.commandFailedWithCode(db.adminCommand({ doTxn: [{op: 'n', ns: t.getFullName(), o: {_id: 0}}], txnNumber: NumberLong(txnNumber++) @@ -98,7 +98,7 @@ ErrorCodes.InvalidOptions, 'doTxn should fail on "no op" operations.'); - // Illegal operation type 'c' (command). + jsTestLog("Illegal operation type 'c' (command)."); assert.commandFailedWithCode(db.adminCommand({ doTxn: [{op: 'c', ns: t.getCollection('$cmd').getFullName(), o: {applyOps: []}}], txnNumber: NumberLong(txnNumber++) @@ -106,13 +106,14 @@ ErrorCodes.InvalidOptions, 'doTxn should fail on commands.'); - // No transaction number in an otherwise valid operation. + jsTestLog("No transaction number in an otherwise valid operation."); assert.commandFailedWithCode( db.adminCommand({doTxn: [{"op": "i", "ns": t.getFullName(), "o": {_id: 5, x: 17}}]}), ErrorCodes.InvalidOptions, 'doTxn should fail when no transaction number is given.'); - // Session IDs and transaction numbers on sub-ops are not allowed + jsTestLog("Session IDs and transaction numbers on sub-ops are not allowed"); + jsTestLog("doTxn should fail when inner transaction contains session id."); var lsid = {id: UUID()}; res = assert.commandFailedWithCode( db.runCommand({ @@ -128,6 +129,7 @@ ErrorCodes.FailedToParse, 'doTxn should fail when inner transaction contains session id.'); + jsTestLog("doTxn should fail when inner transaction contains transaction number."); res = assert.commandFailedWithCode( db.runCommand({ doTxn: [{ @@ -142,6 +144,7 @@ ErrorCodes.FailedToParse, 'doTxn should fail when inner transaction contains transaction number.'); + jsTestLog("doTxn should fail when inner transaction contains statement id."); res = assert.commandFailedWithCode( db.runCommand({ doTxn: [{ @@ -155,7 +158,7 @@ ErrorCodes.FailedToParse, 'doTxn should fail when inner transaction contains statement id.'); - // Malformed operation with unexpected field 'x'. + jsTestLog("Malformed operation with unexpected field 'x'."); assert.commandFailedWithCode( db.adminCommand({doTxn: [{op: 'i', ns: t.getFullName(), o: {_id: 0}, x: 1}]}), ErrorCodes.FailedToParse, @@ -186,10 +189,12 @@ // Insert, delete, and update operations on non-existent collections/databases should return // NamespaceNotFound. + jsTestLog("testCrudOperationOnNonExistentNamespace"); testCrudOperationOnNonExistentNamespace('i', {_id: 0}, {}, ErrorCodes.NamespaceNotFound); testCrudOperationOnNonExistentNamespace('d', {_id: 0}, {}, ErrorCodes.NamespaceNotFound); testCrudOperationOnNonExistentNamespace('u', {x: 0}, {_id: 0}, ErrorCodes.NamespaceNotFound); + jsTestLog("Valid insert"); assert.commandWorked(db.createCollection(t.getName())); var a = assert.commandWorked(db.adminCommand({ doTxn: [{"op": "i", "ns": t.getFullName(), "o": {_id: 5, x: 17}}], @@ -198,6 +203,7 @@ assert.eq(1, t.find().count(), "Valid insert failed"); assert.eq(true, a.results[0], "Bad result value for valid insert"); + jsTestLog("Duplicate insert"); a = assert.commandWorked(db.adminCommand({ doTxn: [{"op": "i", "ns": t.getFullName(), "o": {_id: 5, x: 17}}], txnNumber: NumberLong(txnNumber++) @@ -208,12 +214,14 @@ var o = {_id: 5, x: 17}; assert.eq(o, t.findOne(), "Mismatching document inserted."); + jsTestLog("doTxn should fail on insert of object with empty array element"); // 'o' field is an empty array. assert.commandFailed( db.adminCommand( {doTxn: [{op: 'i', ns: t.getFullName(), o: []}], txnNumber: NumberLong(txnNumber++)}), 'doTxn should fail on insert of object with empty array element'); + jsTestLog("two valid updates"); var res = assert.commandWorked(db.runCommand({ doTxn: [ {op: "u", ns: t.getFullName(), o2: {_id: 5}, o: {$set: {x: 18}}}, @@ -230,7 +238,7 @@ assert.eq(true, res.results[0], "Bad result value for valid update"); assert.eq(true, res.results[1], "Bad result value for valid update"); - // preCondition fully matches + jsTestLog("preCondition fully matches"); res = assert.commandWorked(db.runCommand({ doTxn: [ {op: "u", ns: t.getFullName(), o2: {_id: 5}, o: {$set: {x: 20}}}, @@ -248,7 +256,7 @@ assert.eq(true, res.results[0], "Bad result value for valid update"); assert.eq(true, res.results[1], "Bad result value for valid update"); - // preCondition doesn't match ns + jsTestLog("preCondition doesn't match ns"); res = assert.commandFailed(db.runCommand({ doTxn: [ {op: "u", ns: t.getFullName(), o2: {_id: 5}, o: {$set: {x: 22}}}, @@ -260,7 +268,7 @@ assert.eq(o, t.findOne(), "preCondition didn't match, but ops were still applied"); - // preCondition doesn't match query + jsTestLog("preCondition doesn't match query"); res = assert.commandFailed(db.runCommand({ doTxn: [ {op: "u", ns: t.getFullName(), o2: {_id: 5}, o: {$set: {x: 22}}}, @@ -272,6 +280,7 @@ assert.eq(o, t.findOne(), "preCondition didn't match, but ops were still applied"); + jsTestLog("upsert disallowed"); res = assert.commandFailed(db.runCommand({ doTxn: [ {op: "u", ns: t.getFullName(), o2: {_id: 5}, o: {$set: {x: 22}}}, @@ -285,6 +294,7 @@ // When applying a "u" (update) op, we default to 'UpdateNode' update semantics, and $set // operations add new fields in lexicographic order. + jsTestLog("$set field addition order"); res = assert.commandWorked(db.adminCommand({ doTxn: [ {"op": "i", "ns": t.getFullName(), "o": {_id: 6}}, @@ -295,6 +305,7 @@ assert.eq(t.findOne({_id: 6}), {_id: 6, a: 2, z: 1}); // Note: 'a' and 'z' have been sorted. // 'ModifierInterface' semantics are not supported, so an update with {$v: 0} should fail. + jsTestLog("Fail update with {$v:0}"); res = assert.commandFailed(db.adminCommand({ doTxn: [ {"op": "i", "ns": t.getFullName(), "o": {_id: 7}}, @@ -311,6 +322,7 @@ // When we explicitly specify {$v: 1}, we should get 'UpdateNode' update semantics, and $set // operations get performed in lexicographic order. + jsTestLog("update with {$v:1}"); res = assert.commandWorked(db.adminCommand({ doTxn: [ {"op": "i", "ns": t.getFullName(), "o": {_id: 8}}, |