[pypy-svn] r40481 - in pypy/dist/pypy/tool/build: . test web web/test web/theme

guido at codespeak.net guido at codespeak.net
Wed Mar 14 14:46:59 CET 2007


Author: guido
Date: Wed Mar 14 14:46:55 2007
New Revision: 40481

Modified:
   pypy/dist/pypy/tool/build/metaserver.py
   pypy/dist/pypy/tool/build/test/test_pypybuilder.py
   pypy/dist/pypy/tool/build/web/app.py
   pypy/dist/pypy/tool/build/web/test/test_app.py
   pypy/dist/pypy/tool/build/web/theme/style.css
Log:
Updated functional test, changed status colours, made that the connection to the
server is now persistent, re-connecting on failures, removed unused stub.


Modified: pypy/dist/pypy/tool/build/metaserver.py
==============================================================================
--- pypy/dist/pypy/tool/build/metaserver.py	(original)
+++ pypy/dist/pypy/tool/build/metaserver.py	Wed Mar 14 14:46:55 2007
@@ -25,9 +25,6 @@
             return False
     return True
 
-def make_id(build):
-    """ generate a unique, but predictable id for a build """
-
 class MetaServer(object):
     """ the build meta-server
 

Modified: pypy/dist/pypy/tool/build/test/test_pypybuilder.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_pypybuilder.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_pypybuilder.py	Wed Mar 14 14:46:55 2007
@@ -139,9 +139,9 @@
 
     # then we request a compilation for sysinfo foo=1, obviously this can not
     # be fulfilled yet
-    ispath, data = compile(foo=1)
-    assert not ispath
-    assert 'no suitable build server' in data
+    data = compile(foo=1)
+    assert not data.get('path')
+    assert 'no suitable build server' in data['message']
     queued = get_info('_queued')
     assert len(queued) == 1
 
@@ -157,9 +157,9 @@
         # 4 * SLEEP_INTERVAL seconds to fake the compilation... here we should
         # (if all is well) still be compiling
         
-        ispath, data = compile(foo=1)
-        assert not ispath
-        assert 'in progress' in data
+        data = compile(foo=1)
+        assert not data.get('path')
+        assert 'in progress' in data['message']
 
         waiting = get_info('_waiting')
         assert len(waiting) == 1
@@ -177,8 +177,8 @@
 
         # now a new request for the same build should return in a path being
         # returned
-        ispath, data = compile(foo=1)
-        assert ispath
+        data = compile(foo=1)
+        assert data['path']
 
         queued = get_info('_queued')
         assert len(queued) == 0

Modified: pypy/dist/pypy/tool/build/web/app.py
==============================================================================
--- pypy/dist/pypy/tool/build/web/app.py	(original)
+++ pypy/dist/pypy/tool/build/web/app.py	Wed Mar 14 14:46:55 2007
@@ -34,6 +34,7 @@
     """ base class for pages that communicate with the server
     """
     exposed = True
+    _channel_holder = []
 
     def __init__(self, config, gateway=None):
         self.config = config
@@ -45,27 +46,49 @@
 
         from pypy.tool.build import metaserver_instance
         from pypy.tool.build.web.app import MetaServerAccessor
-        ret = MetaServerAccessor(metaserver_instance).%s(%s)
-        channel.send(ret)
+        msi = MetaServerAccessor(metaserver_instance)
+        while 1:
+            try:
+                methodname, args = channel.receive()
+                ret = getattr(msi, methodname)(*args)
+                channel.send(ret)
+            except IOError: # XXX anything else?
+                break
         channel.close()
     """
 
-    def call_method(self, methodname, args=''):
+    def call_method(self, methodname, args=()):
         """ calls a method on the server
         
             methodname is the name of the method to call, args is a string
             which is _interpolated_ into the method call (so if you want to
             pass the integers 1 and 2 as arguments, 'args' will become '1, 2')
         """
-        conference = execnetconference.conference(self.gateway,
-                                                  self.config.port, False)
-        channel = conference.remote_exec(self.remote_code % (self.config.path,
-                                                             methodname,
-                                                             args))
-        ret = channel.receive()
-        channel.close()
+        performed = False
+        if self._channel_holder:
+            channel = self._channel_holder[0]
+            try:
+                channel.send((methodname, args))
+                ret = channel.receive()
+            except:
+                exc, e, tb = py.std.sys.exc_info()
+                del tb
+                print ('exception occurred when calling %s(%s): '
+                       '%s - %s' % (methodname, args, exc, e))
+            else:
+                performed = True
+        if not performed:
+            conference = execnetconference.conference(self.gateway,
+                                                      self.config.port, False)
+            channel = conference.remote_exec(self.remote_code % (
+                                             self.config.path,))
+            channel.send((methodname, args))
+            ret = channel.receive()
+            while self._channel_holder:
+                self._channel_holder.pop()
+            self._channel_holder.append(channel)
         return ret
-
+    
     def init_gateway(self):
         if self.config.server in ['localhost', '127.0.0.1']:
             gw = py.execnet.PopenGateway()
@@ -132,7 +155,7 @@
                 fix_html(template.unicode(self.get_info())))
 
     def get_info(self):
-        bpinfo, brstr = self.call_method('buildrequest', '"%s"' % (self._buildid,))
+        bpinfo, brstr = self.call_method('buildrequest', (self._buildid,))
         br = BuildRequest.fromstring(brstr)
         if bpinfo == None:
             bpinfo = {}

Modified: pypy/dist/pypy/tool/build/web/test/test_app.py
==============================================================================
--- pypy/dist/pypy/tool/build/web/test/test_app.py	(original)
+++ pypy/dist/pypy/tool/build/web/test/test_app.py	Wed Mar 14 14:46:55 2007
@@ -273,3 +273,26 @@
         url = s.buildurl(req.id())
         assert url == 'http://foo/bar'
 
+class TestServerPage(object):
+    def test_call_method_simple(self):
+        p = ServerPage(fake.Container(port=build_config.testport, path=str(path)),
+                       py.execnet.PopenGateway())
+        ret = p.call_method('status', [])
+        assert ret
+
+    def test_call_method_reconnect(self):
+        p = ServerPage(fake.Container(port=build_config.testport, path=str(path)),
+                       py.execnet.PopenGateway())
+        ret = p.call_method('status', [])
+        assert len(p._channel_holder) == 1
+        channel = p._channel_holder[0]
+        
+        ret = p.call_method('status', [])
+        assert len(p._channel_holder) == 1
+        assert p._channel_holder[0] is channel
+        channel.close()
+
+        ret = p.call_method('status', [])
+        assert len(p._channel_holder) == 1
+        assert p._channel_holder is not channel
+

Modified: pypy/dist/pypy/tool/build/web/theme/style.css
==============================================================================
--- pypy/dist/pypy/tool/build/web/theme/style.css	(original)
+++ pypy/dist/pypy/tool/build/web/theme/style.css	Wed Mar 14 14:46:55 2007
@@ -30,14 +30,14 @@
 }
 
 .done {
-  color: blue;
+  color: green;
 }
 
 .in_progress {
-  color: green;
+  color: yellow;
 }
 
 .waiting {
-  color: yellow;
+  color: orange;
 }
 



More information about the Pypy-commit mailing list