[Neo-report] r2350 gregory - in /trunk/neo/tests: functional/ zodb/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Oct 12 14:17:32 CEST 2010


Author: gregory
Date: Tue Oct 12 14:17:31 2010
New Revision: 2350

Log:
Generate randomly the listening ports.

Modified:
    trunk/neo/tests/functional/__init__.py
    trunk/neo/tests/functional/testClient.py
    trunk/neo/tests/functional/testCluster.py
    trunk/neo/tests/functional/testMaster.py
    trunk/neo/tests/functional/testStorage.py
    trunk/neo/tests/zodb/__init__.py
    trunk/neo/tests/zodb/testRecovery.py

Modified: trunk/neo/tests/functional/__init__.py
==============================================================================
--- trunk/neo/tests/functional/__init__.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/__init__.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -19,6 +19,7 @@ import os
 import sys
 import time
 import ZODB
+import socket
 import signal
 import random
 import MySQLdb
@@ -160,8 +161,7 @@ class NEOProcess(object):
 
 class NEOCluster(object):
 
-    def __init__(self, db_list, master_node_count=1,
-                 partitions=1, replicas=0, port_base=10000,
+    def __init__(self, db_list, master_node_count=1, partitions=1, replicas=0,
                  db_user='neo', db_password='neo',
                  db_super_user=DB_ADMIN, db_super_password=DB_PASSWD,
                  cleanup_on_delete=False, temp_dir=None,
@@ -178,7 +178,7 @@ class NEOCluster(object):
         if clear_databases:
             self.setupDB()
         self.process_dict = {}
-        self.last_port = port_base
+        self.port_set = set()
         if temp_dir is None:
             temp_dir = tempfile.mkdtemp(prefix='neo_')
             print 'Using temp directory %r.' % (temp_dir, )
@@ -234,9 +234,21 @@ class NEOCluster(object):
             NEOProcess(command, uuid, arguments))
 
     def __allocatePort(self):
-        port = self.last_port
-        self.last_port += 1
-        return port
+        for i in range(10):
+            port = random.randrange(30000, 40000)
+            if port in self.port_set:
+                continue
+            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.
+                    self.port_set.add(port)
+                    return port
+            finally:
+                s.close()
+        raise RuntimeError, "Can't find port"
 
     def __allocateUUID(self):
         uuid = os.urandom(16)

Modified: trunk/neo/tests/functional/testClient.py
==============================================================================
--- trunk/neo/tests/functional/testClient.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/testClient.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -68,7 +68,6 @@ class ClientTests(NEOFunctionalTest):
         NEOFunctionalTest.setUp(self)
         self.neo = NEOCluster(
             ['test_neo1', 'test_neo2', 'test_neo3', 'test_neo4'],
-            port_base=20000,
             replicas=2,
             master_node_count=1,
             temp_dir=self.getTempDirectory()

Modified: trunk/neo/tests/functional/testCluster.py
==============================================================================
--- trunk/neo/tests/functional/testCluster.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/testCluster.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -32,7 +32,7 @@ class ClusterTests(NEOFunctionalTest):
             self.neo.stop()
 
     def testClusterBreaks(self):
-        self.neo = NEOCluster(['test_neo1'], port_base=20000,
+        self.neo = NEOCluster(['test_neo1'],
                 master_node_count=1, temp_dir=self.getTempDirectory())
         neoctl = self.neo.getNEOCTL()
         self.neo.setupDB()
@@ -43,7 +43,7 @@ class ClusterTests(NEOFunctionalTest):
         self.neo.expectClusterVerifying()
 
     def testClusterBreaksWithTwoNodes(self):
-        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
+        self.neo = NEOCluster(['test_neo1', 'test_neo2'],
                  partitions=2, master_node_count=1, replicas=0,
                  temp_dir=self.getTempDirectory())
         neoctl = self.neo.getNEOCTL()
@@ -55,7 +55,7 @@ class ClusterTests(NEOFunctionalTest):
         self.neo.expectClusterVerifying()
 
     def testClusterDoesntBreakWithTwoNodesOneReplica(self):
-        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
+        self.neo = NEOCluster(['test_neo1', 'test_neo2'],
                          partitions=2, replicas=1, master_node_count=1,
                          temp_dir=self.getTempDirectory())
         neoctl = self.neo.getNEOCTL()
@@ -68,7 +68,7 @@ class ClusterTests(NEOFunctionalTest):
 
     def testElectionWithManyMasters(self):
         MASTER_COUNT = 20
-        self.neo = NEOCluster(['test_neo1', 'test_neo2'], port_base=20000,
+        self.neo = NEOCluster(['test_neo1', 'test_neo2'],
             partitions=10, replicas=0, master_node_count=MASTER_COUNT,
             temp_dir=self.getTempDirectory())
         neoctl = self.neo.getNEOCTL()

Modified: trunk/neo/tests/functional/testMaster.py
==============================================================================
--- trunk/neo/tests/functional/testMaster.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/testMaster.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -26,8 +26,7 @@ class MasterTests(NEOFunctionalTest):
 
     def setUp(self):
         NEOFunctionalTest.setUp(self)
-        self.neo = NEOCluster([], port_base=20000,
-                master_node_count=MASTER_NODE_COUNT,
+        self.neo = NEOCluster([], master_node_count=MASTER_NODE_COUNT,
                 temp_dir=self.getTempDirectory())
         self.neo.stop()
         self.neo.start()

Modified: trunk/neo/tests/functional/testStorage.py
==============================================================================
--- trunk/neo/tests/functional/testStorage.py [iso-8859-1] (original)
+++ trunk/neo/tests/functional/testStorage.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -49,7 +49,7 @@ class StorageTests(NEOFunctionalTest):
             partitions=10, master_node_count=2):
         # create a neo cluster
         self.neo = NEOCluster(['test_neo%d' % i for i in xrange(storage_number)],
-            port_base=20000, master_node_count=master_node_count,
+            master_node_count=master_node_count,
             partitions=partitions, replicas=replicas,
             temp_dir=self.getTempDirectory(),
             clear_databases=True,

Modified: trunk/neo/tests/zodb/__init__.py
==============================================================================
--- trunk/neo/tests/zodb/__init__.py [iso-8859-1] (original)
+++ trunk/neo/tests/zodb/__init__.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -23,8 +23,7 @@ class ZODBTestCase(NEOFunctionalTest):
 
     def setUp(self):
         NEOFunctionalTest.setUp(self)
-        self.neo = NEOCluster(['test_neo1'],
-                partitions=1, replicas=0, port_base=20000,
+        self.neo = NEOCluster(['test_neo1'], partitions=1, replicas=0,
                 master_node_count=1, temp_dir=self.getTempDirectory())
         self.neo.stop()
         self.neo.setupDB()

Modified: trunk/neo/tests/zodb/testRecovery.py
==============================================================================
--- trunk/neo/tests/zodb/testRecovery.py [iso-8859-1] (original)
+++ trunk/neo/tests/zodb/testRecovery.py [iso-8859-1] Tue Oct 12 14:17:31 2010
@@ -32,8 +32,7 @@ class RecoveryTests(ZODBTestCase, Storag
         dst_temp_dir = self.getTempDirectory() + '-dst'
         if not os.path.exists(dst_temp_dir):
             os.makedirs(dst_temp_dir)
-        self.neo_dst = NEOCluster(['test_neo1-dst'],
-                partitions=1, replicas=0, port_base=10000,
+        self.neo_dst = NEOCluster(['test_neo1-dst'], partitions=1, replicas=0,
                 master_node_count=1, temp_dir=dst_temp_dir)
         self.neo_dst.stop()
         self.neo_dst.setupDB()





More information about the Neo-report mailing list