[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/ Updated the mechanism to select test server ports to remove a source
Jim Fulton
jim at zope.com
Fri Aug 29 08:29:59 EDT 2008
Log message for revision 90581:
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/trunk/src/ZEO/tests/ConnectionTests.py
U ZODB/trunk/src/ZEO/tests/forker.py
U ZODB/trunk/src/ZEO/tests/testZEO.py
-=-
Modified: ZODB/trunk/src/ZEO/tests/ConnectionTests.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/ConnectionTests.py 2008-08-29 12:29:56 UTC (rev 90580)
+++ ZODB/trunk/src/ZEO/tests/ConnectionTests.py 2008-08-29 12:29:58 UTC (rev 90581)
@@ -166,8 +166,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/trunk/src/ZEO/tests/forker.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/forker.py 2008-08-29 12:29:56 UTC (rev 90580)
+++ ZODB/trunk/src/ZEO/tests/forker.py 2008-08-29 12:29:58 UTC (rev 90581)
@@ -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/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py 2008-08-29 12:29:56 UTC (rev 90580)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py 2008-08-29 12:29:58 UTC (rev 90581)
@@ -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
@@ -146,28 +145,6 @@
self.assertNotEquals(ZODB.utils.z64, storage3.lastTransaction())
storage3.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