8000 00438: Fix ThreadedVSOCKSocketStreamTest (GH-119465) (GH-119479) (#11… · fedora-python/cpython@cc2b987 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc2b987

Browse files
miss-islingtonvstinner
authored andcommitted
00438: Fix ThreadedVSOCKSocketStreamTest (pythonGH-119465) (pythonGH-119479) (python#119484)
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 <vstinner@python.org> (cherry picked from commit e94dbe4) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 0dff1c8 commit cc2b987

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
@@ -39,6 +39,7 @@
3939
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4040
MAIN_TIMEOUT = 60.0
4141

42+
VMADDR_CID_LOCAL = 1
4243
VSOCKPORT = 1234
4344
AIX = platform.system() == "AIX"
4445

@@ -112,8 +113,8 @@ def _have_socket_qipcrtr():
112113

113114
def _have_socket_vsock():
114115
"""Check whether AF_VSOCK sockets are supported on this host."""
115-
ret = get_cid() is not None
116-
return ret
116+
cid = get_cid()
117+
return (cid is not None)
117118

118119

119120
@contextlib.contextmanager
@@ -438,8 +439,6 @@ def clientTearDown(self):
438439
@unittest.skipIf(fcntl is None, "need fcntl")
439440
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
440441
'VSOCK sockets required for this test.')
441-
@unittest.skipUnless(get_cid() != 2,
442-
"This test can only be run on a virtual guest.")
443442
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
444443

445444
def __init__(self, methodName='runTest'):
@@ -460,6 +459,9 @@ def clientSetUp(self):
460459
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
461460
self.addCleanup(self.cli.close)
462461
cid = get_cid()
462+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
463+
# gh-119461: Use the local communication address (loopback)
464+
cid = VMADDR_CID_LOCAL
463465
self.cli.connect((cid, VSOCKPORT))
464466

465467
def testStream(self):

0 commit comments

Comments
 (0)
0