jstests/sharding/change_stream_error_label.js
// error label generation logic for change stream getMores.
error label generation logic for change stream getMores.
error label generation logic for change stream getMores .
function testFailGetMoreAfterCursorCheckoutFailpoint({mongos, errorCode, expectedLabel}) {
    errorCode = ErrorCodes.doMongosRewrite(mongos, errorCode);
    assert.commandWorked(testDB.adminCommand({
        configureFailPoint: "failGetMoreAfterCursorCheckout",
        mode: "alwaysOn",
        data: {"errorCode": errorCode}
    }));
    const aggCmdRes = assert.commandWorked(
        coll.runCommand("aggregate", {pipeline: [{$changeStream: {}}], cursor: {}}));
    const getMoreRes = assert.commandFailedWithCode(
        testDB.runCommand({getMore: aggCmdRes.cursor.id, collection: coll.getName()}), errorCode);
    const errorLabels = (getMoreRes.errorLabels || []);
    assert.eq("errorLabels" in getMoreRes, expectedLabel, getMoreRes);
    assert.eq(errorLabels.includes("ResumableChangeStreamError"), expectedLabel, getMoreRes);
    assert.commandWorked(
        testDB.adminCommand({configureFailPoint: "failGetMoreAfterCursorCheckout", mode: "off"}));
}
function testFailGetMoreAfterCursorCheckoutFailpoint ( { mongos , errorCode , expectedLabel } ) { errorCode = ErrorCodes . doMongosRewrite ( mongos , errorCode ) ; assert . commandWorked ( testDB . adminCommand ( { configureFailPoint : "failGetMoreAfterCursorCheckout" , mode : "alwaysOn" , data : { "errorCode" : errorCode } } ) ) ; const aggCmdRes = assert . commandWorked ( coll . runCommand ( "aggregate" , { pipeline : [ { $changeStream : { } } ] , cursor : { } } ) ) ; const getMoreRes = assert . commandFailedWithCode ( testDB . runCommand ( { getMore : aggCmdRes . cursor . id , collection : coll . getName ( ) } ) , errorCode ) ; const errorLabels = ( getMoreRes . errorLabels || [ ] ) ; assert . eq ( "errorLabels" in getMoreRes , expectedLabel , getMoreRes ) ; assert . eq ( errorLabels . includes ( "ResumableChangeStreamError" ) , expectedLabel , getMoreRes ) ; assert . commandWorked ( testDB . adminCommand ( { configureFailPoint : "failGetMoreAfterCursorCheckout" , mode : "off" } ) ) ; }
error label generation logic for change stream getMores.
error label generation logic for change stream getMores .
// Activate the failpoint and set the exception that it will throw. // Now open a valid $changeStream cursor... // ... run a getMore using the cursorID from the original command response, and confirm that the // expected error was thrown... /// ... and confirm that the label is present or absent depending on the "expectedLabel" value. // Finally, disable the failpoint.