jstests/sharding/internal_txns/retryable_writes_retry_in_different_batches.js
// Test that the response to a retried findAndModify command contains the "retriedStmtId" field.
Test that the response to a retried findAndModify command contains the "retriedStmtId" field.
Test that the response to a retried findAndModify command contains the " retriedStmtId " field .
function runFindAndModifyTest(db, coll, makeSessionOptionsFunc) {
    const {initialSessionOpts, retrySessionOpts} = makeSessionOptionsFunc();
    jsTest.log(`Test executing a findAndModify statement in a command in ${
        tojson(initialSessionOpts)} then retrying it in a command in ${tojson(retrySessionOpts)}`);
    const cmdObj = {
        findAndModify: kCollName,
        query: {_id: 1, x: 0},
        update: {$inc: {x: 1}},
        upsert: true,
        stmtId: stmtId1
    };
    const [initialRes] = runCommandsWithSessionOpts(db, [cmdObj], initialSessionOpts);
    const [retryRes] = runCommandsWithSessionOpts(db, [cmdObj], retrySessionOpts);
    assert.eq(initialRes.lastErrorObject, retryRes.lastErrorObject);
    assert.eq(initialRes.value, retryRes.value);
    assert(!initialRes.hasOwnProperty("retriedStmtIds"));
    assert.eq(retryRes.retriedStmtId, stmtId1);
    assert.eq(coll.find({_id: 1, x: 1}).itcount(), 1);
    assert.commandWorked(coll.remove({}));
}
function runFindAndModifyTest ( db , coll , makeSessionOptionsFunc ) { const { initialSessionOpts , retrySessionOpts } = makeSessionOptionsFunc ( ) ; jsTest . log ( ` ${ tojson ( initialSessionOpts ) } ${ tojson ( retrySessionOpts ) } ` ) ; const cmdObj = { findAndModify : kCollName , query : { _id : 1 , x : 0 } , update : { $inc : { x : 1 } } , upsert : true , stmtId : stmtId1 } ; const [ initialRes ] = runCommandsWithSessionOpts ( db , [ cmdObj ] , initialSessionOpts ) ; const [ retryRes ] = runCommandsWithSessionOpts ( db , [ cmdObj ] , retrySessionOpts ) ; assert . eq ( initialRes . lastErrorObject , retryRes . lastErrorObject ) ; assert . eq ( initialRes . value , retryRes . value ) ; assert ( ! initialRes . hasOwnProperty ( "retriedStmtIds" ) ) ; assert . eq ( retryRes . retriedStmtId , stmtId1 ) ; assert . eq ( coll . find ( { _id : 1 , x : 1 } ) . itcount ( ) , 1 ) ; assert . commandWorked ( coll . remove ( { } ) ) ; }
Test that the response to a retried findAndModify command contains the "retriedStmtId" field.
Test that the response to a retried findAndModify command contains the " retriedStmtId " field .