Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / src / php / tests / interop / xds_empty_call.php
1 <?php
2 /*
3  *
4  * Copyright 2021 gRPC authors.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 $autoload_path = realpath(dirname(__FILE__).'/../../vendor/autoload.php');
21 require_once $autoload_path;
22
23 // This script is used to launch 1 single EmptyCall RPC, most likely
24 // for the purpose of starting such RPC asynchronously away from the
25 // main PHP xDS interop client src/php/tests/interop/xds_client.php.
26
27 // This script is launched from src/php/bin/xds_manager.py. The result
28 // of this RPC will be aggregated and reported back to the main runner
29 // from there.
30
31 $args = getopt('', ['server:', 'num:',
32                     'metadata:', 'timeout_sec:']);
33 $TIMEOUT_US = 30 * 1e6; // 30 seconds
34
35 $server_address = $args['server'];
36 $num = $args['num'];
37
38 $stub = new Grpc\Testing\TestServiceClient($server_address, [
39     'credentials' => Grpc\ChannelCredentials::createInsecure()
40 ]);
41
42 $empty_request = new Grpc\Testing\EmptyMessage();
43
44 $timeout = $args['timeout_sec'] ? $args['timeout_sec'] * 1e6 : $TIMEOUT_US;
45 $metadata = [];
46 if ($args['metadata']) {
47     $metadata = unserialize($args['metadata']);
48 }
49
50 $call = $stub->EmptyCall($empty_request,
51                          $metadata,
52                          ['timeout' => $timeout]);
53 list($response, $status) = $call->wait();
54 exit($status->code);