[Fix Flake] Fix contextvar test issue (#38076)

`//src/python/grpcio_tests/tests/unit:_contextvars_propagation_test` is very flaky, mainly in two ways:
1. Failing with error `Error in bind for address '/tmp/grpc_fullstack_test.sock': Address already in use`.
2. Failing with timeout without any error.

#### Address already in use error
This is because we're reusing the same path for all test cases: 5011420f16/src/python/grpcio_tests/tests/unit/_contextvars_propagation_test.py (L31)

#### Timeout error
We're deleting tmp file after test is done:
5011420f16/src/python/grpcio_tests/tests/unit/_contextvars_propagation_test.py (L64-L66)

This might cause Core fail to connect to channel with error: `connect failed: addr: unix:/tmp/grpc_fullstack_test.sock error: No such file or directory`, Core will keep retrying and thus causing the test to timeout.

To make things worse, we're using multiple threads in one of the test case, leading to an even higher rate of flakiness.

This PR fix the issue by using different address for different test runs.

<!--

If you know who should review your pull request, please assign it to that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the appropriate
lang label.

-->

Closes #38076

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38076 from XuanWang-Amos:fix_contextvar_test 93ab2b350f
PiperOrigin-RevId: 693812629
pull/37782/merge
Xuan Wang 3 weeks ago committed by Copybara-Service
parent c4682fe259
commit d53dde77dc
  1. 4
      src/python/grpcio_tests/tests/unit/_contextvars_propagation_test.py

@ -17,7 +17,7 @@ import contextlib
import logging
import os
import queue
import sys
import tempfile
import threading
import unittest
@ -28,7 +28,7 @@ from tests.unit import test_common
_SERVICE_NAME = "test"
_UNARY_UNARY = "UnaryUnary"
_REQUEST = b"0000"
_UDS_PATH = "/tmp/grpc_fullstack_test.sock"
_UDS_PATH = os.path.join(tempfile.mkdtemp(), "grpc_fullstack_test.sock")
def _unary_unary_handler(request, context):

Loading…
Cancel
Save