aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests/unit/_cython/_server_test.py
blob: bbd25457b3e5c82bf2b56430f55e1f2b072e9404 (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
# Copyright 2017 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.
"""Test servers at the level of the Cython API."""

import threading
import time
import unittest

from grpc._cython import cygrpc


class Test(unittest.TestCase):

    def test_lonely_server(self):
        server_call_completion_queue = cygrpc.CompletionQueue()
        server_shutdown_completion_queue = cygrpc.CompletionQueue()
        server = cygrpc.Server(None)
        server.register_completion_queue(server_call_completion_queue)
        server.register_completion_queue(server_shutdown_completion_queue)
        port = server.add_http2_port(b'[::]:0')
        server.start()

        server_request_call_tag = 'server_request_call_tag'
        server_request_call_start_batch_result = server.request_call(
            server_call_completion_queue, server_call_completion_queue,
            server_request_call_tag)

        time.sleep(4)

        server_shutdown_tag = 'server_shutdown_tag'
        server_shutdown_result = server.shutdown(
            server_shutdown_completion_queue, server_shutdown_tag)
        server_request_call_event = server_call_completion_queue.poll()
        server_shutdown_event = server_shutdown_completion_queue.poll()


if __name__ == '__main__':
    unittest.main(verbosity=2)