|
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 |
| 66 | + |
| 67 | + |
60 | 68 | def _assert_retries_equal(retry, retry2): |
61 | 69 | # Retry instances cannot be directly compared, because their predicates are |
62 | 70 | # different instances of the same function. We thus manually compare their other |
@@ -416,17 +424,27 @@ def init(self, *args, **kwargs): |
416 | 424 | assert client.transport._ssl_channel_credentials == mock_ssl_creds |
417 | 425 |
|
418 | 426 |
|
419 | | -def test_init_emulator(monkeypatch): |
| 427 | +def test_init_emulator(monkeypatch, creds): |
420 | 428 | monkeypatch.setenv("PUBSUB_EMULATOR_HOST", "/foo/bar:123") |
421 | 429 | # NOTE: When the emulator host is set, a custom channel will be used, so |
422 | 430 | # no credentials (mock ot otherwise) can be passed in. |
423 | | - client = publisher.Client() |
| 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) |
424 | 442 |
|
425 | 443 | # Establish that a gRPC request would attempt to hit the emulator host. |
426 | 444 | # |
427 | 445 | # Sadly, there seems to be no good way to do this without poking at |
428 | 446 | # the private API of gRPC. |
429 | | - channel = client._transport.publish._channel |
| 447 | + channel = client._transport.publish._thunk("")._channel |
430 | 448 | # Behavior to include dns prefix changed in gRPCv1.63 |
431 | 449 | grpc_major, grpc_minor = [int(part) for part in grpc.__version__.split(".")[0:2]] |
432 | 450 | if grpc_major > 1 or (grpc_major == 1 and grpc_minor >= 63): |
|
0 commit comments