'Test that the first child, not lowest child pid is returned.
Test creates following process tree:
sudo +
+--rootwrap +
+--bash+
+--sleep 100
and tests that pid of `bash\' command is returned.'

def test_get_root_helper_child_pid_returns_first_child(self):

    def wait_for_sleep_is_spawned(parent_pid):
        proc_tree = utils.execute(['pstree', parent_pid], check_exit_code=False)
        processes = [command.strip() for command in proc_tree.split('---') if command]
        if processes:
            return ('sleep' == processes[(-1)])
    cmd = ['bash', '-c', '(sleep    100)']
    proc = async_process.AsyncProcess(cmd, run_as_root=True)
    proc.start()
    sudo_pid = proc._process.pid
    common_utils.wait_until_true(functools.partial(wait_for_sleep_is_spawned, sudo_pid), sleep=0.1)
    child_pid = utils.get_root_helper_child_pid(sudo_pid, cmd, run_as_root=True)
    self.assertIsNotNone(child_pid, 'get_root_helper_child_pid    is    expected    to    return    the    pid    of    the    bash    process')
    self._addcleanup_sleep_process(child_pid)
    with open(('/proc/%s/cmdline' % child_pid), 'r') as f_proc_cmdline:
        cmdline = f_proc_cmdline.readline().split('\x00')[0]
    self.assertIn('bash', cmdline)
