Exemple #1
0
function stress_main($args)
{
    mt_srand();
    set_time_limit(0);
    // open socket to listen as metrics server
    $socket = socket_create(AF_INET, SOCK_STREAM, 0);
    socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
    if (@(!socket_bind($socket, 'localhost', $args['metrics_port']))) {
        echo "Cannot create socket for metrics server...\n";
        exit(1);
    }
    socket_listen($socket);
    socket_set_nonblock($socket);
    $start_time = microtime(true);
    $count = 0;
    $deadline = $args['test_duration_secs'] ? $start_time + $args['test_duration_secs'] : false;
    $num_test_cases = count($args['test_cases']);
    $stub = false;
    while (true) {
        $current_time = microtime(true);
        if ($deadline && $current_time > $deadline) {
            break;
        }
        if ($client_connection = socket_accept($socket)) {
            // there is an incoming request, respond with qps metrics
            $input = socket_read($client_connection, 1024);
            $qps = round($count / ($current_time - $start_time));
            socket_write($client_connection, "qps: {$qps}");
            socket_close($client_connection);
        } else {
            // do actual work, run one interop test case
            $args['test_case'] = $args['test_cases'][mt_rand(0, $num_test_cases - 1)];
            $stub = @interop_main($args, $stub);
            ++$count;
        }
    }
    socket_close($socket);
    echo "Number of interop tests run in {$args['test_duration_secs']} " . "seconds: {$count}.\n";
}
Exemple #2
0
        case 'status_code_and_message':
            statusCodeAndMessage($stub);
            break;
        case 'unimplemented_method':
            unimplementedMethod($stub);
            break;
        case 'service_account_creds':
            serviceAccountCreds($stub, $args);
            break;
        case 'compute_engine_creds':
            computeEngineCreds($stub, $args);
            break;
        case 'jwt_token_creds':
            jwtTokenCreds($stub, $args);
            break;
        case 'oauth2_auth_token':
            oauth2AuthToken($stub, $args);
            break;
        case 'per_rpc_creds':
            perRpcCreds($stub, $args);
            break;
        default:
            echo "Unsupported test case {$test_case}\n";
            exit(1);
    }
    return $stub;
}
if (isset($_SERVER['PHP_SELF']) && preg_match('/interop_client/', $_SERVER['PHP_SELF'])) {
    $args = getopt('', ['server_host:', 'server_port:', 'test_case:', 'use_tls::', 'use_test_ca::', 'server_host_override:', 'oauth_scope:', 'default_service_account:']);
    interop_main($args);
}