Open jiasli opened 7 months ago
Thank you for opening this issue, we will look into it.
I am unable to reproduce this issue locally And from the error message, it doesn't seem like a issue with the logic of the test itself~ Could you retry this test in pipeline or consider manually recording the yaml file for this test locally?
From this line
self = <urllib3.connection.HTTPSConnection object at 0x7f7f078f1990>
we can see self
is urllib3.connection.HTTPSConnection
which is indeed an instance of urllib3.connection.HTTPConnection
.
After some debugging, I found during a normal live test (AZURE_TEST_RUN_LIVE=1
), at site-packages/urllib3/connectionpool.py:416
,
conn.request(method, url, **httplib_request_kw)
the conn.request
call is redirected to vcr.stubs.VCRConnection.request
(site-packages/vcr/stubs/__init__.py:209
), not urllib3.connection.HTTPConnection.request
(site-packages/urllib3/connection.py:244
), so I guess in the failed test, urllib3.connection.HTTPSConnection
has not been patched yet, but the name urllib3.connection.HTTPConnection
has been patched to a vcr.stubs.VCRConnection
.
This is usually caused by a racing condition. However, azdev
uses --forked
on Linux:
if os.name == 'posix':
arguments = ['-x', '-v', '--forked', '-p no:warnings', '--log-level=WARN', '--junit-xml', log_path]
making each test run isolated.
Looking at
these HTTP requests are made in parallel. However, as VCR.py is not designed to be thread-safe (https://github.com/kevin1024/vcrpy/pull/213#issuecomment-144912292), these parallel executions breaks live tests randomly.
In a normal az
command execution, using multi-threading is fine, but these HTTP requests should be executed serially in live tests.
To my surprise, the usage of ThreadPoolExecutor
was introduced very long time ago in https://github.com/Azure/azure-cli/pull/198.
It's still a problem in version 6.0.1. In my tests, I've patched ThreadPoolExecutor and as_completed to work around it.
https://dev.azure.com/azclitools/internal/_build/results?buildId=145445&view=logs&j=c4f33547-49c0-5c65-7824-491d55a01606&t=a7ac92da-e355-5684-e29f-c3f1345ef523