|
57 | 57 | typed_flaky = cast(Callable[[C], C], flaky(max_runs=5, min_passes=1)) |
58 | 58 |
|
59 | 59 |
|
60 | | -# NOTE: This interceptor is required to create an intercept channel. |
61 | | -class _PublisherClientGrpcInterceptor( |
62 | | - grpc.UnaryUnaryClientInterceptor, |
63 | | -): |
64 | | - def intercept_unary_unary(self, continuation, client_call_details, request): |
65 | | - pass |
| 60 | +# Attempt to use `_thunk` to obtain the underlying grpc channel from |
| 61 | +# the intercept channel. Default to obtaining the grpc channel directly |
| 62 | +# for backwards compatibility. |
| 63 | +# TODO(https://github.com/grpc/grpc/issues/38519): Workaround to obtain a channel |
| 64 | +# until a public API is available. |
| 65 | +def get_publish_channel(client): |
| 66 | + try: |
| 67 | + return client._transport.publish._thunk("")._channel |
| 68 | + except AttributeError: |
| 69 | + return client._transport.publish._channel |
66 | 70 |
|
67 | 71 |
|
68 | 72 | def _assert_retries_equal(retry, retry2): |
@@ -424,27 +428,17 @@ def init(self, *args, **kwargs): |
424 | 428 | assert client.transport._ssl_channel_credentials == mock_ssl_creds |
425 | 429 |
|
426 | 430 |
|
427 | | -def test_init_emulator(monkeypatch, creds): |
| 431 | +def test_init_emulator(monkeypatch): |
428 | 432 | monkeypatch.setenv("PUBSUB_EMULATOR_HOST", "/foo/bar:123") |
429 | 433 | # NOTE: When the emulator host is set, a custom channel will be used, so |
430 | 434 | # no credentials (mock ot otherwise) can be passed in. |
431 | | - |
432 | | - # TODO(https://github.com/grpc/grpc/issues/38519): Workaround to create an intercept |
433 | | - # channel (for forwards compatibility) with a channel created by the publisher client |
434 | | - # where target is set to the emulator host. |
435 | | - channel = publisher.Client().transport.grpc_channel |
436 | | - interceptor = _PublisherClientGrpcInterceptor() |
437 | | - intercept_channel = grpc.intercept_channel(channel, interceptor) |
438 | | - transport = publisher.Client.get_transport_class("grpc")( |
439 | | - credentials=creds, channel=intercept_channel |
440 | | - ) |
441 | | - client = publisher.Client(transport=transport) |
| 435 | + client = publisher.Client() |
442 | 436 |
|
443 | 437 | # Establish that a gRPC request would attempt to hit the emulator host. |
444 | 438 | # |
445 | 439 | # Sadly, there seems to be no good way to do this without poking at |
446 | 440 | # the private API of gRPC. |
447 | | - channel = client._transport.publish._thunk("")._channel |
| 441 | + channel = get_publish_channel(client) |
448 | 442 | # Behavior to include dns prefix changed in gRPCv1.63 |
449 | 443 | grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]] |
450 | 444 | if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63): |
|
0 commit comments