Skip to content

Commit ea22705

Browse files
committed
Revert "testing: fix find_display() to speak the real protocol"
This reverts commit aae8463. This does not seem to actually fix the problem, viz the race from: https://github.com/tych0/xcffib/actions/runs/18052535989/job/51377039923 _____________________ TestConnection.test_build_atom_cache _____________________ [gw1] linux -- Python 3.10.18 /home/runner/work/xcffib/xcffib/xcffib_venv/bin/python3 args = (<xcffib.Connection object at 0x7f8d997db8e0>, 4527) self = <xcffib.Connection object at 0x7f8d997db8e0> @functools.wraps(f) def wrapper(*args): self = args[0] self.invalid() try: > return f(*args) xcffib/__init__.py:598: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ xcffib/__init__.py:686: in wait_for_reply self._process_error(error_p[0]) xcffib/__init__.py:673: in _process_error self.invalid() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <xcffib.Connection object at 0x7f8d997db8e0> def invalid(self): if self._conn is None: raise XcffibException("Invalid connection.") err = lib.xcb_connection_has_error(self._conn) if err > 0: > raise ConnectionException(err) E xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors. xcffib/__init__.py:585: ConnectionException During handling of the above exception, another exception occurred: self = <test.test_connection.TestConnection object at 0x7f8d99a0ead0> xproto_test = <test.conftest.XcffibTest object at 0x7f8d997db880> def test_build_atom_cache(self, xproto_test): # This will hold the forward *and* reverse lookups for any given atom atoms = {} cookies = [] # Batch the replies by creating a list of cookies first: for i in range(1, 10000): c = xproto_test.conn.core.GetAtomName(i) cookies.append((i, c)) for i, c in cookies: try: > name = c.reply().name.to_string() test/test_connection.py:306: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ xcffib/__init__.py:341: in reply data = self.conn.wait_for_reply(self.sequence) xcffib/__init__.py:600: in wrapper self.invalid() _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <xcffib.Connection object at 0x7f8d997db8e0> def invalid(self): if self._conn is None: raise XcffibException("Invalid connection.") err = lib.xcb_connection_has_error(self._conn) if err > 0: > raise ConnectionException(err) E xcffib.ConnectionException: xcb connection errors because of socket, pipe and other stream errors. xcffib/__init__.py:585: ConnectionException ----------------------------- Captured stderr call ----------------------------- _XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed _XSERVTransMakeAllCOTSServerListeners: server already running (EE) Fatal server error: (EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE) --------------------------- Captured stderr teardown -------------------------- so let's revert for now since it's an API break. Signed-off-by: Tycho Andersen <[email protected]>
1 parent 4e2e9bf commit ea22705

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

module/testing.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# others who want to test things using xcffib.
1717

1818
import errno
19+
import fcntl
1920
import os
2021
import subprocess
2122
import time
@@ -30,32 +31,17 @@ def lock_path(display):
3031
def find_display():
3132
display = 10
3233
while True:
33-
lock_file = lock_path(display)
34-
3534
try:
36-
with open(lock_file, 'r') as f:
37-
pid = int(f.read().strip())
38-
35+
f = open(lock_path(display), "w+")
3936
try:
40-
os.kill(pid, 0)
41-
display += 1
42-
continue
43-
except (OSError, ProcessLookupError):
44-
try:
45-
os.remove(lock_file)
46-
except FileNotFoundError:
47-
pass
48-
49-
except (FileNotFoundError, ValueError, OSError):
50-
pass
51-
52-
try:
53-
fd = os.open(lock_file, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
54-
os.write(fd, str(os.getpid()).encode())
55-
return display, fd
56-
except FileExistsError:
37+
fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
38+
except OSError:
39+
f.close()
40+
raise
41+
except OSError:
5742
display += 1
5843
continue
44+
return display, f
5945

6046

6147
class XvfbTest:
@@ -117,7 +103,7 @@ def tearDown(self):
117103
# clean up after itself.
118104
try:
119105
os.remove(lock_path(self._display))
120-
os.close(self._display_lock)
106+
self._display_lock.close()
121107
except OSError as e:
122108
# we don't care if it doesn't exist, maybe something crashed and
123109
# cleaned it up during a test.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ xcffib = ["py.typed"]
3838
[project.optional-dependencies]
3939
dev = [
4040
"pytest>=8.4",
41-
"pytest-xdist",
4241
]

0 commit comments

Comments
 (0)