Skip to content

Commit 122dd4f

Browse files
[3.12] [3.13] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-119465) (GH-119479) (#119484)
[3.13] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-119465) (GH-119479) gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-119465) Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host address or the "any" address, use the local communication address (loopback): VMADDR_CID_LOCAL. On Linux 6.9, apparently, the /dev/vsock device is now available but get_cid() returns VMADDR_CID_ANY (-1). (cherry picked from commit c750061) Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit e94dbe4) Co-authored-by: Victor Stinner <[email protected]>
1 parent ddaed62 commit 122dd4f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/test/test_socket.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# test unicode string and carriage return
4545
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4646

47+
VMADDR_CID_LOCAL = 1
4748
VSOCKPORT = 1234
4849
AIX = platform.system() == "AIX"
4950
WSL = "microsoft-standard-WSL" in platform.release()
@@ -128,8 +129,8 @@ def _have_socket_qipcrtr():
128129

129130
def _have_socket_vsock():
130131
"""Check whether AF_VSOCK sockets are supported on this host."""
131-
ret = get_cid() is not None
132-
return ret
132+
cid = get_cid()
133+
return (cid is not None)
133134

134135

135136
def _have_socket_bluetooth():
@@ -485,8 +486,6 @@ def clientTearDown(self):
485486
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
486487
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
487488
'VSOCK sockets required for this test.')
488-
@unittest.skipUnless(get_cid() != 2,
489-
"This test can only be run on a virtual guest.")
490489
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
491490

492491
def __init__(self, methodName='runTest'):
@@ -508,6 +507,9 @@ def clientSetUp(self):
508507
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
509508
self.addCleanup(self.cli.close)
510509
cid = get_cid()
510+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
511+
# gh-119461: Use the local communication address (loopback)
512+
cid = VMADDR_CID_LOCAL
511513
self.cli.connect((cid, VSOCKPORT))
512514

513515
def testStream(self):

0 commit comments

Comments
 (0)