jstests/noPassthrough/socket_disconnect_kills.js
// Returns false if the op was gone from current op
Returns false if the op was gone from current op
Returns false if the op was gone from current op
function check(client, pre, post) {
    const interval = 200;
    const timeout = 10000;
    const socketTimeout = 5000;
    const host = client.host;
    id++;
    let conn =
        new Mongo(`mongodb://${host}/?socketTimeoutMS=${socketTimeout}&appName=${testName}${id}`);
    assert.commandWorked(conn.adminCommand({ping: 1}));
    try {
        assert.throws(function() {
            try {
                pre(conn);
            } catch (e) {
                if (isNetworkError(e)) {
                    throw e;
                }
            }
        }, [], "error doing query: failed: network error while attempting");
        const start = new Date();
        while (1) {
            if (!client.getDB("admin")
                     .aggregate([
                         {$currentOp: {localOps: true}},
                         {$match: {appName: testName + id}},
                     ])
                     .itcount()) {
                return false;
            }
            if (((new Date()).getTime() - start.getTime()) > timeout) {
                return true;
            }
            sleep(interval);
        }
    } finally {
        post();
    }
}
function check ( client , pre , post ) { const interval = 200 ; const timeout = 10000 ; const socketTimeout = 5000 ; const host = client . host ; id ++ ; let conn = new Mongo ( ` ${ host } ${ socketTimeout } ${ testName } ${ id } ` ) ; assert . commandWorked ( conn . adminCommand ( { ping : 1 } ) ) ; try { assert . throws ( function ( ) { try { pre ( conn ) ; } catch ( e ) { if ( isNetworkError ( e ) ) { throw e ; } } } , [ ] , "error doing query: failed: network error while attempting" ) ; const start = new Date ( ) ; while ( 1 ) { if ( ! client . getDB ( "admin" ) . aggregate ( [ { $currentOp : { localOps : true } } , { $match : { appName : testName + id } } , ] ) . itcount ( ) ) { return false ; } if ( ( ( new Date ( ) ) . getTime ( ) - start . getTime ( ) ) > timeout ) { return true ; } sleep ( interval ) ; } } finally { post ( ) ; } }
Returns false if the op was gone from current op
Returns false if the op was gone from current op
// Make a socket which will timeout // Make sure it works at all // Make sure that whatever operation we ran had a network error // Spin until the op leaves currentop, or timeout passes