| 1 |
# Copyright 2020 The gRPC Authors |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
"""Tests of grpc_channelz.v1.channelz.""" |
| 15 |
|
| 16 |
import asyncio |
| 17 |
import logging |
| 18 |
import unittest |
| 19 |
|
| 20 |
import grpc |
| 21 |
from grpc.experimental import aio |
| 22 |
from grpc_channelz.v1 import channelz |
| 23 |
from grpc_channelz.v1 import channelz_pb2 |
| 24 |
from grpc_channelz.v1 import channelz_pb2_grpc |
| 25 |
|
| 26 |
from tests.unit.framework.common import test_constants |
| 27 |
from tests_aio.unit._test_base import AioTestBase |
| 28 |
|
| 29 |
_SUCCESSFUL_UNARY_UNARY = '/test/SuccessfulUnaryUnary' |
| 30 |
_FAILED_UNARY_UNARY = '/test/FailedUnaryUnary' |
| 31 |
_SUCCESSFUL_STREAM_STREAM = '/test/SuccessfulStreamStream' |
| 32 |
|
| 33 |
_REQUEST = b'\x00\x00\x00' |
| 34 |
_RESPONSE = b'\x01\x01\x01' |
| 35 |
|
| 36 |
_DISABLE_REUSE_PORT = (('grpc.so_reuseport', 0),) |
| 37 |
_ENABLE_CHANNELZ = (('grpc.enable_channelz', 1),) |
| 38 |
_DISABLE_CHANNELZ = (('grpc.enable_channelz', 0),) |
| 39 |
|
| 40 |
_LARGE_UNASSIGNED_ID = 10000 |
| 41 |
|
| 42 |
|
| 43 |
async def _successful_unary_unary(request, servicer_context): |
| 44 |
return _RESPONSE |
| 45 |
|
| 46 |
|
| 47 |
async def _failed_unary_unary(request, servicer_context): |
| 48 |
servicer_context.set_code(grpc.StatusCode.INTERNAL) |
| 49 |
servicer_context.set_details("Channelz Test Intended Failure") |
| 50 |
|
| 51 |
|
| 52 |
async def _successful_stream_stream(request_iterator, servicer_context): |
| 53 |
async for _ in request_iterator: |
| 54 |
yield _RESPONSE |
| 55 |
|
| 56 |
|
| 57 |
class _GenericHandler(grpc.GenericRpcHandler): |
| 58 |
|
| 59 |
def service(self, handler_call_details): |
| 60 |
if handler_call_details.method == _SUCCESSFUL_UNARY_UNARY: |
| 61 |
return grpc.unary_unary_rpc_method_handler(_successful_unary_unary) |
| 62 |
elif handler_call_details.method == _FAILED_UNARY_UNARY: |
| 63 |
return grpc.unary_unary_rpc_method_handler(_failed_unary_unary) |
| 64 |
elif handler_call_details.method == _SUCCESSFUL_STREAM_STREAM: |
| 65 |
return grpc.stream_stream_rpc_method_handler( |
| 66 |
_successful_stream_stream) |
| 67 |
else: |
| 68 |
return None |
| 69 |
|
| 70 |
|
| 71 |
class _ChannelServerPair: |
| 72 |
|
| 73 |
def __init__(self): |
| 74 |
self.address = '' |
| 75 |
self.server = None |
| 76 |
self.channel = None |
| 77 |
self.server_ref_id = None |
| 78 |
self.channel_ref_id = None |
| 79 |
|
| 80 |
async def start(self): |
| 81 |
# Server will enable channelz service |
| 82 |
self.server = aio.server(options=_DISABLE_REUSE_PORT + _ENABLE_CHANNELZ) |
| 83 |
port = self.server.add_insecure_port('[::]:0') |
| 84 |
self.address = 'localhost:%d' % port |
| 85 |
self.server.add_generic_rpc_handlers((_GenericHandler(),)) |
| 86 |
await self.server.start() |
| 87 |
|
| 88 |
# Channel will enable channelz service... |
| 89 |
self.channel = aio.insecure_channel(self.address, |
| 90 |
options=_ENABLE_CHANNELZ) |
| 91 |
|
| 92 |
async def bind_channelz(self, channelz_stub): |
| 93 |
resp = await channelz_stub.GetTopChannels( |
| 94 |
channelz_pb2.GetTopChannelsRequest(start_channel_id=0)) |
| 95 |
for channel in resp.channel: |
| 96 |
if channel.data.target == self.address: |
| 97 |
self.channel_ref_id = channel.ref.channel_id |
| 98 |
|
| 99 |
resp = await channelz_stub.GetServers( |
| 100 |
channelz_pb2.GetServersRequest(start_server_id=0)) |
| 101 |
self.server_ref_id = resp.server[-1].ref.server_id |
| 102 |
|
| 103 |
async def stop(self): |
| 104 |
await self.channel.close() |
| 105 |
await self.server.stop(None) |
| 106 |
|
| 107 |
|
| 108 |
async def _create_channel_server_pairs(n, channelz_stub=None): |
| 109 |
"""Create channel-server pairs.""" |
| 110 |
pairs = [_ChannelServerPair() for i in range(n)] |
| 111 |
for pair in pairs: |
| 112 |
await pair.start() |
| 113 |
if channelz_stub: |
| 114 |
await pair.bind_channelz(channelz_stub) |
| 115 |
return pairs |
| 116 |
|
| 117 |
|
| 118 |
async def _destroy_channel_server_pairs(pairs): |
| 119 |
for pair in pairs: |
| 120 |
await pair.stop() |
| 121 |
|
| 122 |
|
| 123 |
class ChannelzServicerTest(AioTestBase): |
| 124 |
|
| 125 |
async def setUp(self): |
| 126 |
# This server is for Channelz info fetching only |
| 127 |
# It self should not enable Channelz |
| 128 |
self._server = aio.server(options=_DISABLE_REUSE_PORT + |
| 129 |
_DISABLE_CHANNELZ) |
| 130 |
port = self._server.add_insecure_port('[::]:0') |
| 131 |
channelz.add_channelz_servicer(self._server) |
| 132 |
await self._server.start() |
| 133 |
|
| 134 |
# This channel is used to fetch Channelz info only |
| 135 |
# Channelz should not be enabled |
| 136 |
self._channel = aio.insecure_channel('localhost:%d' % port, |
| 137 |
options=_DISABLE_CHANNELZ) |
| 138 |
self._channelz_stub = channelz_pb2_grpc.ChannelzStub(self._channel) |
| 139 |
|
| 140 |
async def tearDown(self): |
| 141 |
await self._channel.close() |
| 142 |
await self._server.stop(None) |
| 143 |
|
| 144 |
async def _get_server_by_ref_id(self, ref_id): |
| 145 |
"""Server id may not be consecutive""" |
| 146 |
resp = await self._channelz_stub.GetServers( |
| 147 |
channelz_pb2.GetServersRequest(start_server_id=ref_id)) |
| 148 |
self.assertEqual(ref_id, resp.server[0].ref.server_id) |
| 149 |
return resp.server[0] |
| 150 |
|
| 151 |
async def _send_successful_unary_unary(self, pair): |
| 152 |
call = pair.channel.unary_unary(_SUCCESSFUL_UNARY_UNARY)(_REQUEST) |
| 153 |
self.assertEqual(grpc.StatusCode.OK, await call.code()) |
| 154 |
|
| 155 |
async def _send_failed_unary_unary(self, pair): |
| 156 |
try: |
| 157 |
await pair.channel.unary_unary(_FAILED_UNARY_UNARY)(_REQUEST) |
| 158 |
except grpc.RpcError: |
| 159 |
return |
| 160 |
else: |
| 161 |
self.fail("This call supposed to fail") |
| 162 |
|
| 163 |
async def _send_successful_stream_stream(self, pair): |
| 164 |
call = pair.channel.stream_stream(_SUCCESSFUL_STREAM_STREAM)(iter( |
| 165 |
[_REQUEST] * test_constants.STREAM_LENGTH)) |
| 166 |
cnt = 0 |
| 167 |
async for _ in call: |
| 168 |
cnt += 1 |
| 169 |
self.assertEqual(cnt, test_constants.STREAM_LENGTH) |
| 170 |
|
| 171 |
async def test_get_top_channels_high_start_id(self): |
| 172 |
pairs = await _create_channel_server_pairs(1) |
| 173 |
|
| 174 |
resp = await self._channelz_stub.GetTopChannels( |
| 175 |
channelz_pb2.GetTopChannelsRequest( |
| 176 |
start_channel_id=_LARGE_UNASSIGNED_ID)) |
| 177 |
self.assertEqual(len(resp.channel), 0) |
| 178 |
self.assertEqual(resp.end, True) |
| 179 |
|
| 180 |
await _destroy_channel_server_pairs(pairs) |
| 181 |
|
| 182 |
async def test_successful_request(self): |
| 183 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 184 |
|
| 185 |
await self._send_successful_unary_unary(pairs[0]) |
| 186 |
resp = await self._channelz_stub.GetChannel( |
| 187 |
channelz_pb2.GetChannelRequest(channel_id=pairs[0].channel_ref_id)) |
| 188 |
|
| 189 |
self.assertEqual(resp.channel.data.calls_started, 1) |
| 190 |
self.assertEqual(resp.channel.data.calls_succeeded, 1) |
| 191 |
self.assertEqual(resp.channel.data.calls_failed, 0) |
| 192 |
|
| 193 |
await _destroy_channel_server_pairs(pairs) |
| 194 |
|
| 195 |
async def test_failed_request(self): |
| 196 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 197 |
|
| 198 |
await self._send_failed_unary_unary(pairs[0]) |
| 199 |
resp = await self._channelz_stub.GetChannel( |
| 200 |
channelz_pb2.GetChannelRequest(channel_id=pairs[0].channel_ref_id)) |
| 201 |
self.assertEqual(resp.channel.data.calls_started, 1) |
| 202 |
self.assertEqual(resp.channel.data.calls_succeeded, 0) |
| 203 |
self.assertEqual(resp.channel.data.calls_failed, 1) |
| 204 |
|
| 205 |
await _destroy_channel_server_pairs(pairs) |
| 206 |
|
| 207 |
async def test_many_requests(self): |
| 208 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 209 |
|
| 210 |
k_success = 7 |
| 211 |
k_failed = 9 |
| 212 |
for i in range(k_success): |
| 213 |
await self._send_successful_unary_unary(pairs[0]) |
| 214 |
for i in range(k_failed): |
| 215 |
await self._send_failed_unary_unary(pairs[0]) |
| 216 |
resp = await self._channelz_stub.GetChannel( |
| 217 |
channelz_pb2.GetChannelRequest(channel_id=pairs[0].channel_ref_id)) |
| 218 |
self.assertEqual(resp.channel.data.calls_started, k_success + k_failed) |
| 219 |
self.assertEqual(resp.channel.data.calls_succeeded, k_success) |
| 220 |
self.assertEqual(resp.channel.data.calls_failed, k_failed) |
| 221 |
|
| 222 |
await _destroy_channel_server_pairs(pairs) |
| 223 |
|
| 224 |
async def test_many_requests_many_channel(self): |
| 225 |
k_channels = 4 |
| 226 |
pairs = await _create_channel_server_pairs(k_channels, |
| 227 |
self._channelz_stub) |
| 228 |
k_success = 11 |
| 229 |
k_failed = 13 |
| 230 |
for i in range(k_success): |
| 231 |
await self._send_successful_unary_unary(pairs[0]) |
| 232 |
await self._send_successful_unary_unary(pairs[2]) |
| 233 |
for i in range(k_failed): |
| 234 |
await self._send_failed_unary_unary(pairs[1]) |
| 235 |
await self._send_failed_unary_unary(pairs[2]) |
| 236 |
|
| 237 |
# The first channel saw only successes |
| 238 |
resp = await self._channelz_stub.GetChannel( |
| 239 |
channelz_pb2.GetChannelRequest(channel_id=pairs[0].channel_ref_id)) |
| 240 |
self.assertEqual(resp.channel.data.calls_started, k_success) |
| 241 |
self.assertEqual(resp.channel.data.calls_succeeded, k_success) |
| 242 |
self.assertEqual(resp.channel.data.calls_failed, 0) |
| 243 |
|
| 244 |
# The second channel saw only failures |
| 245 |
resp = await self._channelz_stub.GetChannel( |
| 246 |
channelz_pb2.GetChannelRequest(channel_id=pairs[1].channel_ref_id)) |
| 247 |
self.assertEqual(resp.channel.data.calls_started, k_failed) |
| 248 |
self.assertEqual(resp.channel.data.calls_succeeded, 0) |
| 249 |
self.assertEqual(resp.channel.data.calls_failed, k_failed) |
| 250 |
|
| 251 |
# The third channel saw both successes and failures |
| 252 |
resp = await self._channelz_stub.GetChannel( |
| 253 |
channelz_pb2.GetChannelRequest(channel_id=pairs[2].channel_ref_id)) |
| 254 |
self.assertEqual(resp.channel.data.calls_started, k_success + k_failed) |
| 255 |
self.assertEqual(resp.channel.data.calls_succeeded, k_success) |
| 256 |
self.assertEqual(resp.channel.data.calls_failed, k_failed) |
| 257 |
|
| 258 |
# The fourth channel saw nothing |
| 259 |
resp = await self._channelz_stub.GetChannel( |
| 260 |
channelz_pb2.GetChannelRequest(channel_id=pairs[3].channel_ref_id)) |
| 261 |
self.assertEqual(resp.channel.data.calls_started, 0) |
| 262 |
self.assertEqual(resp.channel.data.calls_succeeded, 0) |
| 263 |
self.assertEqual(resp.channel.data.calls_failed, 0) |
| 264 |
|
| 265 |
await _destroy_channel_server_pairs(pairs) |
| 266 |
|
| 267 |
async def test_many_subchannels(self): |
| 268 |
k_channels = 4 |
| 269 |
pairs = await _create_channel_server_pairs(k_channels, |
| 270 |
self._channelz_stub) |
| 271 |
k_success = 17 |
| 272 |
k_failed = 19 |
| 273 |
for i in range(k_success): |
| 274 |
await self._send_successful_unary_unary(pairs[0]) |
| 275 |
await self._send_successful_unary_unary(pairs[2]) |
| 276 |
for i in range(k_failed): |
| 277 |
await self._send_failed_unary_unary(pairs[1]) |
| 278 |
await self._send_failed_unary_unary(pairs[2]) |
| 279 |
|
| 280 |
for i in range(k_channels): |
| 281 |
gc_resp = await self._channelz_stub.GetChannel( |
| 282 |
channelz_pb2.GetChannelRequest( |
| 283 |
channel_id=pairs[i].channel_ref_id)) |
| 284 |
# If no call performed in the channel, there shouldn't be any subchannel |
| 285 |
if gc_resp.channel.data.calls_started == 0: |
| 286 |
self.assertEqual(len(gc_resp.channel.subchannel_ref), 0) |
| 287 |
continue |
| 288 |
|
| 289 |
# Otherwise, the subchannel should exist |
| 290 |
self.assertGreater(len(gc_resp.channel.subchannel_ref), 0) |
| 291 |
gsc_resp = await self._channelz_stub.GetSubchannel( |
| 292 |
channelz_pb2.GetSubchannelRequest( |
| 293 |
subchannel_id=gc_resp.channel.subchannel_ref[0]. |
| 294 |
subchannel_id)) |
| 295 |
self.assertEqual(gc_resp.channel.data.calls_started, |
| 296 |
gsc_resp.subchannel.data.calls_started) |
| 297 |
self.assertEqual(gc_resp.channel.data.calls_succeeded, |
| 298 |
gsc_resp.subchannel.data.calls_succeeded) |
| 299 |
self.assertEqual(gc_resp.channel.data.calls_failed, |
| 300 |
gsc_resp.subchannel.data.calls_failed) |
| 301 |
|
| 302 |
await _destroy_channel_server_pairs(pairs) |
| 303 |
|
| 304 |
async def test_server_call(self): |
| 305 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 306 |
|
| 307 |
k_success = 23 |
| 308 |
k_failed = 29 |
| 309 |
for i in range(k_success): |
| 310 |
await self._send_successful_unary_unary(pairs[0]) |
| 311 |
for i in range(k_failed): |
| 312 |
await self._send_failed_unary_unary(pairs[0]) |
| 313 |
|
| 314 |
resp = await self._get_server_by_ref_id(pairs[0].server_ref_id) |
| 315 |
self.assertEqual(resp.data.calls_started, k_success + k_failed) |
| 316 |
self.assertEqual(resp.data.calls_succeeded, k_success) |
| 317 |
self.assertEqual(resp.data.calls_failed, k_failed) |
| 318 |
|
| 319 |
await _destroy_channel_server_pairs(pairs) |
| 320 |
|
| 321 |
async def test_many_subchannels_and_sockets(self): |
| 322 |
k_channels = 4 |
| 323 |
pairs = await _create_channel_server_pairs(k_channels, |
| 324 |
self._channelz_stub) |
| 325 |
k_success = 3 |
| 326 |
k_failed = 5 |
| 327 |
for i in range(k_success): |
| 328 |
await self._send_successful_unary_unary(pairs[0]) |
| 329 |
await self._send_successful_unary_unary(pairs[2]) |
| 330 |
for i in range(k_failed): |
| 331 |
await self._send_failed_unary_unary(pairs[1]) |
| 332 |
await self._send_failed_unary_unary(pairs[2]) |
| 333 |
|
| 334 |
for i in range(k_channels): |
| 335 |
gc_resp = await self._channelz_stub.GetChannel( |
| 336 |
channelz_pb2.GetChannelRequest( |
| 337 |
channel_id=pairs[i].channel_ref_id)) |
| 338 |
|
| 339 |
# If no call performed in the channel, there shouldn't be any subchannel |
| 340 |
if gc_resp.channel.data.calls_started == 0: |
| 341 |
self.assertEqual(len(gc_resp.channel.subchannel_ref), 0) |
| 342 |
continue |
| 343 |
|
| 344 |
# Otherwise, the subchannel should exist |
| 345 |
self.assertGreater(len(gc_resp.channel.subchannel_ref), 0) |
| 346 |
gsc_resp = await self._channelz_stub.GetSubchannel( |
| 347 |
channelz_pb2.GetSubchannelRequest( |
| 348 |
subchannel_id=gc_resp.channel.subchannel_ref[0]. |
| 349 |
subchannel_id)) |
| 350 |
self.assertEqual(len(gsc_resp.subchannel.socket_ref), 1) |
| 351 |
|
| 352 |
gs_resp = await self._channelz_stub.GetSocket( |
| 353 |
channelz_pb2.GetSocketRequest( |
| 354 |
socket_id=gsc_resp.subchannel.socket_ref[0].socket_id)) |
| 355 |
self.assertEqual(gsc_resp.subchannel.data.calls_started, |
| 356 |
gs_resp.socket.data.streams_started) |
| 357 |
self.assertEqual(0, gs_resp.socket.data.streams_failed) |
| 358 |
# Calls started == messages sent, only valid for unary calls |
| 359 |
self.assertEqual(gsc_resp.subchannel.data.calls_started, |
| 360 |
gs_resp.socket.data.messages_sent) |
| 361 |
|
| 362 |
await _destroy_channel_server_pairs(pairs) |
| 363 |
|
| 364 |
async def test_streaming_rpc(self): |
| 365 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 366 |
# In C++, the argument for _send_successful_stream_stream is message length. |
| 367 |
# Here the argument is still channel idx, to be consistent with the other two. |
| 368 |
await self._send_successful_stream_stream(pairs[0]) |
| 369 |
|
| 370 |
gc_resp = await self._channelz_stub.GetChannel( |
| 371 |
channelz_pb2.GetChannelRequest(channel_id=pairs[0].channel_ref_id)) |
| 372 |
self.assertEqual(gc_resp.channel.data.calls_started, 1) |
| 373 |
self.assertEqual(gc_resp.channel.data.calls_succeeded, 1) |
| 374 |
self.assertEqual(gc_resp.channel.data.calls_failed, 0) |
| 375 |
# Subchannel exists |
| 376 |
self.assertGreater(len(gc_resp.channel.subchannel_ref), 0) |
| 377 |
|
| 378 |
while True: |
| 379 |
gsc_resp = await self._channelz_stub.GetSubchannel( |
| 380 |
channelz_pb2.GetSubchannelRequest( |
| 381 |
subchannel_id=gc_resp.channel.subchannel_ref[0]. |
| 382 |
subchannel_id)) |
| 383 |
if gsc_resp.subchannel.data.calls_started == gsc_resp.subchannel.data.calls_succeeded + gsc_resp.subchannel.data.calls_failed: |
| 384 |
break |
| 385 |
self.assertEqual(gsc_resp.subchannel.data.calls_started, 1) |
| 386 |
self.assertEqual(gsc_resp.subchannel.data.calls_failed, 0) |
| 387 |
self.assertEqual(gsc_resp.subchannel.data.calls_succeeded, 1) |
| 388 |
# Socket exists |
| 389 |
self.assertEqual(len(gsc_resp.subchannel.socket_ref), 1) |
| 390 |
|
| 391 |
while True: |
| 392 |
gs_resp = await self._channelz_stub.GetSocket( |
| 393 |
channelz_pb2.GetSocketRequest( |
| 394 |
socket_id=gsc_resp.subchannel.socket_ref[0].socket_id)) |
| 395 |
if gs_resp.socket.data.streams_started == gs_resp.socket.data.streams_succeeded + gs_resp.socket.data.streams_failed: |
| 396 |
break |
| 397 |
self.assertEqual(gs_resp.socket.data.streams_started, 1) |
| 398 |
self.assertEqual(gs_resp.socket.data.streams_failed, 0) |
| 399 |
self.assertEqual(gs_resp.socket.data.streams_succeeded, 1) |
| 400 |
self.assertEqual(gs_resp.socket.data.messages_sent, |
| 401 |
test_constants.STREAM_LENGTH) |
| 402 |
self.assertEqual(gs_resp.socket.data.messages_received, |
| 403 |
test_constants.STREAM_LENGTH) |
| 404 |
|
| 405 |
await _destroy_channel_server_pairs(pairs) |
| 406 |
|
| 407 |
async def test_server_sockets(self): |
| 408 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 409 |
|
| 410 |
await self._send_successful_unary_unary(pairs[0]) |
| 411 |
await self._send_failed_unary_unary(pairs[0]) |
| 412 |
|
| 413 |
resp = await self._get_server_by_ref_id(pairs[0].server_ref_id) |
| 414 |
self.assertEqual(resp.data.calls_started, 2) |
| 415 |
self.assertEqual(resp.data.calls_succeeded, 1) |
| 416 |
self.assertEqual(resp.data.calls_failed, 1) |
| 417 |
|
| 418 |
gss_resp = await self._channelz_stub.GetServerSockets( |
| 419 |
channelz_pb2.GetServerSocketsRequest(server_id=resp.ref.server_id, |
| 420 |
start_socket_id=0)) |
| 421 |
# If the RPC call failed, it will raise a grpc.RpcError |
| 422 |
# So, if there is no exception raised, considered pass |
| 423 |
await _destroy_channel_server_pairs(pairs) |
| 424 |
|
| 425 |
async def test_server_listen_sockets(self): |
| 426 |
pairs = await _create_channel_server_pairs(1, self._channelz_stub) |
| 427 |
|
| 428 |
resp = await self._get_server_by_ref_id(pairs[0].server_ref_id) |
| 429 |
self.assertEqual(len(resp.listen_socket), 1) |
| 430 |
|
| 431 |
gs_resp = await self._channelz_stub.GetSocket( |
| 432 |
channelz_pb2.GetSocketRequest( |
| 433 |
socket_id=resp.listen_socket[0].socket_id)) |
| 434 |
# If the RPC call failed, it will raise a grpc.RpcError |
| 435 |
# So, if there is no exception raised, considered pass |
| 436 |
await _destroy_channel_server_pairs(pairs) |
| 437 |
|
| 438 |
async def test_invalid_query_get_server(self): |
| 439 |
with self.assertRaises(aio.AioRpcError) as exception_context: |
| 440 |
await self._channelz_stub.GetServer( |
| 441 |
channelz_pb2.GetServerRequest(server_id=_LARGE_UNASSIGNED_ID)) |
| 442 |
self.assertEqual(grpc.StatusCode.NOT_FOUND, |
| 443 |
exception_context.exception.code()) |
| 444 |
|
| 445 |
async def test_invalid_query_get_channel(self): |
| 446 |
with self.assertRaises(aio.AioRpcError) as exception_context: |
| 447 |
await self._channelz_stub.GetChannel( |
| 448 |
channelz_pb2.GetChannelRequest(channel_id=_LARGE_UNASSIGNED_ID)) |
| 449 |
self.assertEqual(grpc.StatusCode.NOT_FOUND, |
| 450 |
exception_context.exception.code()) |
| 451 |
|
| 452 |
async def test_invalid_query_get_subchannel(self): |
| 453 |
with self.assertRaises(aio.AioRpcError) as exception_context: |
| 454 |
await self._channelz_stub.GetSubchannel( |
| 455 |
channelz_pb2.GetSubchannelRequest( |
| 456 |
subchannel_id=_LARGE_UNASSIGNED_ID)) |
| 457 |
self.assertEqual(grpc.StatusCode.NOT_FOUND, |
| 458 |
exception_context.exception.code()) |
| 459 |
|
| 460 |
async def test_invalid_query_get_socket(self): |
| 461 |
with self.assertRaises(aio.AioRpcError) as exception_context: |
| 462 |
await self._channelz_stub.GetSocket( |
| 463 |
channelz_pb2.GetSocketRequest(socket_id=_LARGE_UNASSIGNED_ID)) |
| 464 |
self.assertEqual(grpc.StatusCode.NOT_FOUND, |
| 465 |
exception_context.exception.code()) |
| 466 |
|
| 467 |
async def test_invalid_query_get_server_sockets(self): |
| 468 |
with self.assertRaises(aio.AioRpcError) as exception_context: |
| 469 |
await self._channelz_stub.GetServerSockets( |
| 470 |
channelz_pb2.GetServerSocketsRequest( |
| 471 |
server_id=_LARGE_UNASSIGNED_ID, |
| 472 |
start_socket_id=0, |
| 473 |
)) |
| 474 |
self.assertEqual(grpc.StatusCode.NOT_FOUND, |
| 475 |
exception_context.exception.code()) |
| 476 |
|
| 477 |
|
| 478 |
if __name__ == '__main__': |
| 479 |
logging.basicConfig(level=logging.DEBUG) |
| 480 |
unittest.main(verbosity=2) |