function _waitForIndicator(node, states, ind, timeout) {
        if (node.length) {
            var nodes = node;
            for(var i = 0; i < nodes.length; i++) {
                if (states.length)
                    _waitForIndicator(nodes[i], states[i], ind, timeout);
                else
                    _waitForIndicator(nodes[i], states, ind, timeout);
            }

            return;
        }

        timeout = timeout || 30000;

        if (!node.getDB) {
            node = self.nodes[node];
        }

        if (!states.length) {
            states = [states];
        }

        print("ReplSetTest waitForIndicator " + ind + " on " + node);
        printjson(states);
        print("ReplSetTest waitForIndicator from node " + node);

        var lastTime = null;
        var currTime = new Date().getTime();
        var status;

        assert.soon(function() {
            try {
                var conn = _callIsMaster();
                if (!conn) {
                    conn = self.liveNodes.slaves[0];
                }

                // Try again to load connection
                if (!conn) return false;

                var getStatusFunc = function() {
                    status = conn.getDB('admin').runCommand({ replSetGetStatus: 1 });
                };

                if (self.keyFile) {
                    // Authenticate connection used for running replSetGetStatus if needed
                    authutil.asCluster(conn, self.keyFile, getStatusFunc);
                } else {
                    getStatusFunc();
                }
            }
            catch (ex) {
                print("ReplSetTest waitForIndicator could not get status: " + tojson(ex));
                return false;
            }

            var printStatus = false;
            if (lastTime == null || (currTime = new Date().getTime()) - (1000 * 5) > lastTime) {
                if (lastTime == null) {
                    print("ReplSetTest waitForIndicator Initial status (timeout : "
                          + timeout + ") :");
                }

                printjson(status);
                lastTime = new Date().getTime();
                printStatus = true;
            }

            if (typeof status.members == 'undefined') {
                return false;
            }

            for(var i = 0; i < status.members.length; i++) {
                if (printStatus) {
                    print("Status for : " + status.members[i].name + ", checking " +
                            node.host + "/" + node.name);
                }

                if (status.members[i].name == node.host || status.members[i].name == node.name) {
                    for(var j = 0; j < states.length; j++) {
                        if (printStatus) {
                            print("Status -- " + " current state: " + status.members[i][ind] +
                                    ",  target state : " + states[j]);
                        }

                        if (typeof(states[j]) != "number") {
                            throw new Error("State was not an number -- type:" +
                                            typeof(states[j]) + ", value:" + states[j]);
                        }
                        if (status.members[i][ind] == states[j]) {
                            return true;
                        }
                    }
                }
            }

            return false;

        }, "waiting for state indicator " + ind + " for " + timeout + "ms", timeout);

        print("ReplSetTest waitForIndicator final status:");
        printjson(status);
    }
/**
     * Wait for a rs indicator to go to a particular state or states.
     * 
     * @param node is a single node or list of nodes, by id or conn
     * @param states is a single state or list of states
     * @param ind is the indicator specified
     * @param timeout how long to wait for the state to be reached
     */
Wait for a rs indicator to go to a particular state or states.

@param node is a single node or list of nodes, by id or conn
@param states is a single state or list of states
@param ind is the indicator specified
@param timeout how long to wait for the state to be reached
Wait for a rs indicator to go to a particular state or states . @param node is a single node or list of nodes by id or conn @param states is a single state or list of states @param ind is the indicator specified @param timeout how long to wait for the state to be reached
function _waitForIndicator(node, states, ind, timeout) {
        if (node.length) {
            var nodes = node;
            for(var i = 0; i < nodes.length; i++) {
                if (states.length)
                    _waitForIndicator(nodes[i], states[i], ind, timeout);
                else
                    _waitForIndicator(nodes[i], states, ind, timeout);
            }
            return;
        }
        timeout = timeout || 30000;
        if (!node.getDB) {
            node = self.nodes[node];
        }
        if (!states.length) {
            states = [states];
        }
        print("ReplSetTest waitForIndicator " + ind + " on " + node);
        printjson(states);
        print("ReplSetTest waitForIndicator from node " + node);
        var lastTime = null;
        var currTime = new Date().getTime();
        var status;
        assert.soon(function() {
            try {
                var conn = _callIsMaster();
                if (!conn) {
                    conn = self.liveNodes.slaves[0];
                }
                if (!conn) return false;
                var getStatusFunc = function() {
                    status = conn.getDB('admin').runCommand({ replSetGetStatus: 1 });
                };
                if (self.keyFile) {
                    authutil.asCluster(conn, self.keyFile, getStatusFunc);
                } else {
                    getStatusFunc();
                }
            }
            catch (ex) {
                print("ReplSetTest waitForIndicator could not get status: " + tojson(ex));
                return false;
            }
            var printStatus = false;
            if (lastTime == null || (currTime = new Date().getTime()) - (1000 * 5) > lastTime) {
                if (lastTime == null) {
                    print("ReplSetTest waitForIndicator Initial status (timeout : "
                          + timeout + ") :");
                }
                printjson(status);
                lastTime = new Date().getTime();
                printStatus = true;
            }
            if (typeof status.members == 'undefined') {
                return false;
            }
            for(var i = 0; i < status.members.length; i++) {
                if (printStatus) {
                    print("Status for : " + status.members[i].name + ", checking " +
                            node.host + "/" + node.name);
                }
                if (status.members[i].name == node.host || status.members[i].name == node.name) {
                    for(var j = 0; j < states.length; j++) {
                        if (printStatus) {
                            print("Status -- " + " current state: " + status.members[i][ind] +
                                    ",  target state : " + states[j]);
                        }
                        if (typeof(states[j]) != "number") {
                            throw new Error("State was not an number -- type:" +
                                            typeof(states[j]) + ", value:" + states[j]);
                        }
                        if (status.members[i][ind] == states[j]) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }, "waiting for state indicator " + ind + " for " + timeout + "ms", timeout);
        print("ReplSetTest waitForIndicator final status:");
        printjson(status);
    }
function _waitForIndicator ( node , states , ind , timeout ) { if ( node . length ) { var nodes = node ; for ( var i = 0 ; i < nodes . length ; i ++ ) { if ( states . length ) _waitForIndicator ( nodes [ i ] , states [ i ] , ind , timeout ) ; else _waitForIndicator ( nodes [ i ] , states , ind , timeout ) ; } return ; } timeout = timeout || 30000 ; if ( ! node . getDB ) { node = self . nodes [ node ] ; } if ( ! states . length ) { states = [ states ] ; } print ( "ReplSetTest waitForIndicator " + ind + " on " + node ) ; printjson ( states ) ; print ( "ReplSetTest waitForIndicator from node " + node ) ; var lastTime = null ; var currTime = new Date ( ) . getTime ( ) ; var status ; assert . soon ( function ( ) { try { var conn = _callIsMaster ( ) ; if ( ! conn ) { conn = self . liveNodes . slaves [ 0 ] ; } if ( ! conn ) return false ; var getStatusFunc = function ( ) { status = conn . getDB ( 'admin' ) . runCommand ( { replSetGetStatus : 1 } ) ; } ; if ( self . keyFile ) { authutil . asCluster ( conn , self . keyFile , getStatusFunc ) ; } else { getStatusFunc ( ) ; } } catch ( ex ) { print ( "ReplSetTest waitForIndicator could not get status: " + tojson ( ex ) ) ; return false ; } var printStatus = false ; if ( lastTime == null || ( currTime = new Date ( ) . getTime ( ) ) - ( 1000 * 5 ) > lastTime ) { if ( lastTime == null ) { print ( "ReplSetTest waitForIndicator Initial status (timeout : " + timeout + ") :" ) ; } printjson ( status ) ; lastTime = new Date ( ) . getTime ( ) ; printStatus = true ; } if ( typeof status . members == 'undefined' ) { return false ; } for ( var i = 0 ; i < status . members . length ; i ++ ) { if ( printStatus ) { print ( "Status for : " + status . members [ i ] . name + ", checking " + node . host + "/" + node . name ) ; } if ( status . members [ i ] . name == node . host || status . members [ i ] . name == node . name ) { for ( var j = 0 ; j < states . length ; j ++ ) { if ( printStatus ) { print ( "Status -- " + " current state: " + status . members [ i ] [ ind ] + ",  target state : " + states [ j ] ) ; } if ( typeof ( states [ j ] ) != "number" ) { throw new Error ( "State was not an number -- type:" + typeof ( states [ j ] ) + ", value:" + states [ j ] ) ; } if ( status . members [ i ] [ ind ] == states [ j ] ) { return true ; } } } } return false ; } , "waiting for state indicator " + ind + " for " + timeout + "ms" , timeout ) ; print ( "ReplSetTest waitForIndicator final status:" ) ; printjson ( status ) ; }
Wait for a rs indicator to go to a particular state or states.
Wait for a rs indicator to go to a particular state or states .
// Try again to load connection // Authenticate connection used for running replSetGetStatus if needed