jstests/fail_point/fail_point.js
/**
 * Performs basic checks on the configureFailPoint and waitForFailPoint command.
 * Also check mongo/util/fail_point_test.cpp for unit tests.
 *
 * @param adminDB {DB} the admin database database object
 */
Performs basic checks on the configureFailPoint and waitForFailPoint command.
Also check mongo/util/fail_point_test.cpp for unit tests.

@param adminDB {DB} the admin database database object
Performs basic checks on the configureFailPoint and waitForFailPoint command . Also check mongo / util / fail_point_test . cpp for unit tests . @param adminDB { DB } the admin database database object
function runBasicTest(adminDB) {
    function expectFailPointState(fpState, expectedMode, expectedData) {
        assert.eq(expectedMode, fpState.mode);
        for (var field in expectedData) {  
            assert.eq(expectedData[field], fpState.data[field]);
        }
        for (field in fpState.data) {
            assert.eq(expectedData[field], fpState.data[field]);
        }
    }
    var res;
    assert.commandFailed(
        adminDB.runCommand({configureFailPoint: 'fpNotExist', mode: 'alwaysOn', data: {x: 1}}));
    assert.commandFailed(
        adminDB.runCommand({configureFailPoint: 'dummy', mode: 'badMode', data: {x: 1}}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 0, {});
    assert.commandFailed(
        adminDB.runCommand({configureFailPoint: 'dummy', mode: {foo: 3}, data: {x: 1}}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 0, {});
    assert.commandFailed(
        adminDB.runCommand({configureFailPoint: 'dummy', mode: true, data: {x: 1}}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 0, {});
    assert.commandFailed(
        adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn', data: 'data'}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 0, {});
    assert.commandWorked(adminDB.runCommand({configureFailPoint: 'dummy', mode: 'off'}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 0, {});
    assert.commandWorked(adminDB.runCommand({configureFailPoint: 'dummy', mode: {skip: 2}}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 4, {});
    assert.commandWorked(
        adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn', data: {x: 1}}));
    res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
    assert.commandWorked(res);
    expectFailPointState(res["failpoint.dummy"], 1, {x: 1});
    var configureFailPointRes = adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn'});
    assert.commandWorked(configureFailPointRes);
    assert.commandFailedWithCode(adminDB.adminCommand({
        waitForFailPoint: "dummy",
        timesEntered: configureFailPointRes.count + 1,
        maxTimeMS: 10
    }),
                                 ErrorCodes.MaxTimeMSExpired);
    assert.commandFailedWithCode(adminDB.adminCommand({waitForFailPoint: "dummy", timesEntered: 1}),
                                 40414);
}
function runBasicTest ( adminDB ) { function expectFailPointState ( fpState , expectedMode , expectedData ) { assert . eq ( expectedMode , fpState . mode ) ; for ( var field in expectedData ) { assert . eq ( expectedData [ field ] , fpState . data [ field ] ) ; } for ( field in fpState . data ) { assert . eq ( expectedData [ field ] , fpState . data [ field ] ) ; } } var res ; assert . commandFailed ( adminDB . runCommand ( { configureFailPoint : 'fpNotExist' , mode : 'alwaysOn' , data : { x : 1 } } ) ) ; assert . commandFailed ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : 'badMode' , data : { x : 1 } } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 0 , { } ) ; assert . commandFailed ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : { foo : 3 } , data : { x : 1 } } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 0 , { } ) ; assert . commandFailed ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : true , data : { x : 1 } } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 0 , { } ) ; assert . commandFailed ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : 'alwaysOn' , data : 'data' } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 0 , { } ) ; assert . commandWorked ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : 'off' } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 0 , { } ) ; assert . commandWorked ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : { skip : 2 } } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 4 , { } ) ; assert . commandWorked ( adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : 'alwaysOn' , data : { x : 1 } } ) ) ; res = adminDB . runCommand ( { getParameter : 1 , "failpoint.dummy" : 1 } ) ; assert . commandWorked ( res ) ; expectFailPointState ( res [ "failpoint.dummy" ] , 1 , { x : 1 } ) ; var configureFailPointRes = adminDB . runCommand ( { configureFailPoint : 'dummy' , mode : 'alwaysOn' } ) ; assert . commandWorked ( configureFailPointRes ) ; assert . commandFailedWithCode ( adminDB . adminCommand ( { waitForFailPoint : "dummy" , timesEntered : configureFailPointRes . count + 1 , maxTimeMS : 10 } ) , ErrorCodes . MaxTimeMSExpired ) ; assert . commandFailedWithCode ( adminDB . adminCommand ( { waitForFailPoint : "dummy" , timesEntered : 1 } ) , 40414 ) ; }
Performs basic checks on the configureFailPoint and waitForFailPoint command.
Performs basic checks on the configureFailPoint and waitForFailPoint command .
// Check that all expected data is present. // Valid only for 1 level field checks // Check that all present data is expected. // A failpoint's state can be read through getParameter by prefixing its name with // "failpoint" // Test non-existing fail point // Test bad mode string // Test bad mode obj // Test bad mode type // Test bad data type // Test setting mode to off. // Test setting mode to skip. // Test good command w/ data // Test that the timeout for waitForFailPoint can be set via maxTimeMS. // Test that waitForFailPoint throws an error when maxTimeMS is not provided.