aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests/fork/client.py
blob: 9a32629ed5a6c9e0bdc65da6aba2207838bd9ac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the GRPC interoperability test client."""

import argparse
import logging
import sys

from tests.fork import methods


def _args():

    def parse_bool(value):
        if value == 'true':
            return True
        if value == 'false':
            return False
        raise argparse.ArgumentTypeError('Only true/false allowed')

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--server_host',
        default="localhost",
        type=str,
        help='the host to which to connect')
    parser.add_argument(
        '--server_port',
        type=int,
        required=True,
        help='the port to which to connect')
    parser.add_argument(
        '--test_case',
        default='large_unary',
        type=str,
        help='the test case to execute')
    parser.add_argument(
        '--use_tls',
        default=False,
        type=parse_bool,
        help='require a secure connection')
    return parser.parse_args()


def _test_case_from_arg(test_case_arg):
    for test_case in methods.TestCase:
        if test_case_arg == test_case.value:
            return test_case
    else:
        raise ValueError('No test case "%s"!' % test_case_arg)


def test_fork():
    logging.basicConfig(level=logging.INFO)
    args = _args()
    if args.test_case == "all":
        for test_case in methods.TestCase:
            test_case.run_test(args)
    else:
        test_case = _test_case_from_arg(args.test_case)
        test_case.run_test(args)


if __name__ == '__main__':
    test_fork()