[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/tests/ Updated the
mechanism to select test server ports to remove a source
Jim Fulton
jim at zope.com
Tue Jul 8 14:51:04 EDT 2008
Log message for revision 88122:
Updated the mechanism to select test server ports to remove a source
of intermittent test failures. In ConnectionTests, a random port was
selected without checking if it was in use. testZEO.get_port (moved
to forker) picked a random port, checking if it was in use, but
clients actually used that port *and* the following one. Now check
that the returned and subsequent ports are free. (Of course, they
could get used betweed the time they're selected and the time they are
used by the test. Oh well.
Changed:
U ZODB/branches/3.8/src/ZEO/tests/ConnectionTests.py
U ZODB/branches/3.8/src/ZEO/tests/forker.py
U ZODB/branches/3.8/src/ZEO/tests/testZEO.py
-=-
Modified: ZODB/branches/3.8/src/ZEO/tests/ConnectionTests.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/tests/ConnectionTests.py 2008-07-08 17:46:50 UTC (rev 88121)
+++ ZODB/branches/3.8/src/ZEO/tests/ConnectionTests.py 2008-07-08 18:51:04 UTC (rev 88122)
@@ -158,8 +158,7 @@
self.addr.append(self._getAddr())
def _getAddr(self):
- # port+1 is also used, so only draw even port numbers
- return 'localhost', random.randrange(25000, 30000, 2)
+ return 'localhost', forker.get_port()
def getConfig(self, path, create, read_only):
raise NotImplementedError
Modified: ZODB/branches/3.8/src/ZEO/tests/forker.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/tests/forker.py 2008-07-08 17:46:50 UTC (rev 88121)
+++ ZODB/branches/3.8/src/ZEO/tests/forker.py 2008-07-08 18:51:04 UTC (rev 88122)
@@ -14,6 +14,7 @@
"""Library for forking storage server and connecting client storage"""
import os
+import random
import sys
import time
import errno
@@ -201,3 +202,29 @@
ack = 'no ack received'
logger.debug('shutdown_zeo_server(): acked: %s' % ack)
s.close()
+
+def get_port():
+ """Return a port that is not in use.
+
+ Checks if a port is in use by trying to connect to it. Assumes it
+ is not in use if connect raises an exception. We actually look for
+ 2 consective free ports because most of the clients of this
+ function will use the returned port and the next one.
+
+ Raises RuntimeError after 10 tries.
+ """
+ for i in range(10):
+ port = random.randrange(20000, 30000)
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ try:
+ s.connect(('localhost', port))
+ s1.connect(('localhost', port+1))
+ except socket.error:
+ # Perhaps we should check value of error too.
+ return port
+ finally:
+ s.close()
+ s1.close()
+ raise RuntimeError("Can't find port")
Modified: ZODB/branches/3.8/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/tests/testZEO.py 2008-07-08 17:46:50 UTC (rev 88121)
+++ ZODB/branches/3.8/src/ZEO/tests/testZEO.py 2008-07-08 18:51:04 UTC (rev 88122)
@@ -18,9 +18,7 @@
import doctest
import logging
import os
-import random
import signal
-import socket
import stat
import tempfile
import threading
@@ -50,6 +48,7 @@
import ZEO.zrpc.connection
from ZEO.tests import forker, Cache, CommitLockTests, ThreadTests
+from ZEO.tests.forker import get_port
import ZEO.tests.ConnectionTests
@@ -128,27 +127,6 @@
finally:
storage2.close()
-def get_port():
- """Return a port that is not in use.
-
- Checks if a port is in use by trying to connect to it. Assumes it
- is not in use if connect raises an exception.
-
- Raises RuntimeError after 10 tries.
- """
- for i in range(10):
- port = random.randrange(20000, 30000)
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- try:
- s.connect(('localhost', port))
- except socket.error:
- # Perhaps we should check value of error too.
- return port
- finally:
- s.close()
- raise RuntimeError("Can't find port")
-
class GenericTests(
# Base class for all ZODB tests
StorageTestBase.StorageTestBase,
More information about the Zodb-checkins
mailing list