Rev 7: Test servers get statically assigned port numbers. in file:///v/home/vila/.bazaar/plugins/local_test_server/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed May 28 12:19:39 BST 2008


At file:///v/home/vila/.bazaar/plugins/local_test_server/

------------------------------------------------------------
revno: 7
revision-id: v.ladeuil+lp at free.fr-20080528111938-d0spqs2co7r2m03c
parent: v.ladeuil+lp at free.fr-20080528105757-6rdlzl1tohf27osd
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Wed 2008-05-28 13:19:38 +0200
message:
  Test servers get statically assigned port numbers.
  
  * tests/test_config.py:
  (TestConfig.test_expand_keywords): Updated for host/port.
  
  * server.py:
  (Server.__init__): host is forced to localhost, use -1 as a
  reserved value for tests. Update config with host and port.
  (Apache2.__init__): Add a port parameter.
  (_servers): Use instances so that port can be statically assigned.
  
  * config.py:
  (Config.__init__): Add default values for host and port.
modified:
  config.py                      __init__.py-20080523170713-0c8mnxio9r41iyhk-1
  server.py                      server.py-20080524160639-rqhbexqatjqbwypw-1
  tests/test_config.py           test_config.py-20080523170715-clr6vz0qdzefftob-1
-------------- next part --------------
=== modified file 'config.py'
--- a/config.py	2008-05-26 19:42:08 +0000
+++ b/config.py	2008-05-28 11:19:38 +0000
@@ -53,7 +53,10 @@
                            var_dir=var_dir,
                            var_run_dir=var_run_dir,
                            var_lock_dir=var_lock_dir,
-                           var_log_dir=var_log_dir)
+                           var_log_dir=var_log_dir,
+                            # Will be updated at server creation
+                           host='example.com' ,port=0,
+                          )
 
     def expand(self, infile, outfile):
         """Expand all the config keywords.

=== modified file 'server.py'
--- a/server.py	2008-05-28 10:57:57 +0000
+++ b/server.py	2008-05-28 11:19:38 +0000
@@ -30,14 +30,15 @@
 
 class Server(object):
 
-    def __init__(self, conf, host='localhost', port=-1):
-        self.config = conf
-        self.host = host
+    def __init__(self, config, port=-1):
+        self.host = 'localhost'
         if port != -1:
             self.port = port
         else:
             # For tests only
             self.port = _get_available_port()
+        config.values.update(host=self.host, port=self.port)
+        self.config = config
 
     def start(self):
         raise NotImplementedError(self.start)
@@ -78,9 +79,8 @@
     # alternative
     _hk_interval = 10.0 # in miliseconds
 
-    def __init__(self):
-        super(Apache2, self).__init__(config.Apache2())
-        self.port = None
+    def __init__(self, port):
+        super(Apache2, self).__init__(config.Apache2(), port)
 
     def start(self):
         infile = open(self.config.config_path)
@@ -178,16 +178,6 @@
         return pid
 
 
-_servers = dict(apache2=Apache2)
-
-def get_server(name):
-    klass = _servers.get(name, None)
-    if klass is None:
-        return None
-    else:
-        return klass()
-
-
 _next_available_port = 49000
 _max_available_port = 49151
 def _get_available_port():
@@ -201,7 +191,7 @@
     bzr test suite).
 
     This function returns an available port in a range chosen in unassigned
-    ones as described in http://www.iana.org/assignments/port-numbers.
+    ones as described in http://www.iana.org/assignments/port-numbers
     """
     global _next_available_port
     global _max_available_port
@@ -210,3 +200,13 @@
         raise ValueError('No more available ports')
     _next_available_port += 1
     return port
+
+
+# The test servers provided use a range of unassigned port numbers as described
+# in http://www.iana.org/assignments/port-numbers
+
+_servers = dict(apache2=Apache2(37000))
+
+def get_server(name):
+    return _servers.get(name, None)
+

=== modified file 'tests/test_config.py'
--- a/tests/test_config.py	2008-05-26 19:42:08 +0000
+++ b/tests/test_config.py	2008-05-28 11:19:38 +0000
@@ -77,6 +77,7 @@
         conf = config.Config('foo')
         content = '''
 my name is %(server_name)s
+my address is %(host)s:%(port)s
 my config is generated under %(etc_dir)s
 my pid is somewhere below %(var_run_dir)s
 I use some lock mechanism which needs something under %(var_lock_dir)s
@@ -87,6 +88,7 @@
         conf.expand(inf, outf)
         expanded = outf.getvalue()
         self.assertContainsRe(expanded, 'my name is foo\n')
+        self.assertContainsRe(expanded, 'my address is example.com:0\n')
         self.assertContainsRe(
             expanded, 'my config is generated under .*/etc\n')
         self.assertContainsRe(



More information about the bazaar-commits mailing list