[pypy-svn] r35565 - in pypy/dist/pypy/tool/build: . bin test

guido at codespeak.net guido at codespeak.net
Mon Dec 11 13:31:47 CET 2006


Author: guido
Date: Mon Dec 11 13:31:43 2006
New Revision: 35565

Modified:
   pypy/dist/pypy/tool/build/bin/client
   pypy/dist/pypy/tool/build/client.py
   pypy/dist/pypy/tool/build/config.py
   pypy/dist/pypy/tool/build/server.py
   pypy/dist/pypy/tool/build/test/fake.py
   pypy/dist/pypy/tool/build/test/test_client.py
   pypy/dist/pypy/tool/build/test/test_pypybuilder.py
   pypy/dist/pypy/tool/build/test/test_server.py
Log:
Added mechanism to allow clients to decide to not accept a build request.


Modified: pypy/dist/pypy/tool/build/bin/client
==============================================================================
--- pypy/dist/pypy/tool/build/bin/client	(original)
+++ pypy/dist/pypy/tool/build/bin/client	Mon Dec 11 13:31:43 2006
@@ -37,6 +37,15 @@
                             type(data),)
                 )
             sysinfo, compileinfo = data
+            accepting = True
+            for checker in config.client_checkers:
+                if not checker(sysinfo, compileinfo):
+                    accepting = False
+                    break
+            channel.send(accepting)
+            if not accepting:
+                print 'refusing compilation'
+                continue
             # XXX we should compile here, using data dict for info
             print 'compilation requested for info %r\n\nbuilding...' % (
                     data,)

Modified: pypy/dist/pypy/tool/build/client.py
==============================================================================
--- pypy/dist/pypy/tool/build/client.py	(original)
+++ pypy/dist/pypy/tool/build/client.py	Mon Dec 11 13:31:43 2006
@@ -23,7 +23,10 @@
         """send a compile job to the client side"""
         self.busy_on = info
         self.channel.send(info)
-        thread.start_new_thread(self.wait_until_done, (info,))
+        accepted = self.channel.receive()
+        if accepted:
+            thread.start_new_thread(self.wait_until_done, (info,))
+        return accepted
 
     def wait_until_done(self, info):
         buildpath = self.server.get_new_buildpath(info)

Modified: pypy/dist/pypy/tool/build/config.py
==============================================================================
--- pypy/dist/pypy/tool/build/config.py	(original)
+++ pypy/dist/pypy/tool/build/config.py	Mon Dec 11 13:31:43 2006
@@ -32,3 +32,7 @@
 # settings for the tests
 testpath = [str(py.magic.autopath().dirpath().dirpath())]
 
+# when considering a compile job, the checkers below will be called (args
+# sysinfo, compileinfo), if one of them returns False the compilation will
+# not be accepted
+client_checkers = []

Modified: pypy/dist/pypy/tool/build/server.py
==============================================================================
--- pypy/dist/pypy/tool/build/server.py	(original)
+++ pypy/dist/pypy/tool/build/server.py	Mon Dec 11 13:31:43 2006
@@ -211,8 +211,9 @@
                         info, client
                     )
                 )
-                client.compile(info)
-                return True
+                accepted = client.compile(info)
+                if accepted:
+                    return True
         self._channel.send(
             'no suitable client available for compilation with info %r' % (
                 info,

Modified: pypy/dist/pypy/tool/build/test/fake.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/fake.py	(original)
+++ pypy/dist/pypy/tool/build/test/fake.py	Mon Dec 11 13:31:43 2006
@@ -27,6 +27,7 @@
             self.channel.send('%s: %r' % (k, v))
         self.channel.send(None)
         self.busy_on = info
+        return True
 
 class FakeServer(object):
     def __init__(self, builddirpath):

Modified: pypy/dist/pypy/tool/build/test/test_client.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_client.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_client.py	Mon Dec 11 13:31:43 2006
@@ -26,8 +26,11 @@
 
 def test_compile():
     info = ({'foo': 1}, {'bar': 2})
-    c1.compile(info)
-    c1.channel.receive()
+    c1c.send(True) # notifying we 'accept' the compile
+    accepted = c1.compile(info)
+    assert accepted
+    ret = c1.channel.receive()
+    assert ret == info # this was still in the buffer
     c1.channel.send('foo bar')
     c1.channel.send(None)
 
@@ -58,3 +61,9 @@
     cw.close()
     assert c.buffer == ['foo', 'bar', 'baz', None]
 
+def test_failed_checker():
+    info = ({'foo': 1}, {'bar': 2})
+    c1c.send(False) # notifying we _don't_ 'accept' the compile
+    accepted = c1.compile(info)
+    assert not accepted
+

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	Mon Dec 11 13:31:43 2006
@@ -20,7 +20,7 @@
 def test_functional_1():
     if not py.test.pypybuilder_option.functional:
         py.test.skip('skipping functional test, use --functional to run it')
-        
+    
     # XXX this one is a bit messy, it's a quick functional test for the whole
     # system, but for instance contains time.sleep()s to make sure all threads
     # get the time to perform tasks and such... 
@@ -59,6 +59,12 @@
     compgw = py.execnet.PopenGateway()
     compconf = execnetconference.conference(compgw, config.port)
 
+    # clients normally respond with a boolean on a compilation request... to
+    # allow the code to continue, already put some Trues (meaning 'I accept
+    # the job') in the buffers
+    cc1.send(True)
+    cc2.send(True)
+
     # this one should fail because there's no client found for foo = 3
     compc = compconf.remote_exec(code % (config.testpath, 'foo1 at bar.com',
                                             {'foo': 3}))
@@ -98,6 +104,9 @@
     cgw3 = py.execnet.PopenGateway()
     cc3 = client.init(cgw3, sysconfig3, port=config.port, testing=True)
 
+    # add True to the buffer just like we did for channels 1 and 2
+    cc3.send(True)
+
     # again a bit of waiting may be desired
     py.std.time.sleep(SLEEP_INTERVAL)
 

Modified: pypy/dist/pypy/tool/build/test/test_server.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_server.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_server.py	Mon Dec 11 13:31:43 2006
@@ -50,17 +50,22 @@
     ret = svr.compile('test at domain.com', (info, None))
     assert not ret[0]
     assert ret[1].find('found a suitable client') > -1
-    assert svr._channel.receive().find('going to send compile job') > -1
-    assert c1.channel.receive() == 'foo: 1'
-    assert c1.channel.receive() is None
+    ret = svr._channel.receive()
+    assert ret.find('going to send compile job') > -1
+    ret = c1.channel.receive()
+    assert ret == 'foo: 1'
+    ret = c1.channel.receive()
+    assert ret is None
     py.test.raises(IndexError, "c2.channel.receive()")
 
     svr.compile('test at domain.com', ({'foo': 3}, None))
-    assert svr._channel.receive().find('no suitable client available') > -1
+    ret = svr._channel.receive()
+    assert ret.find('no suitable client available') > -1
 
     info = {'bar': [3]}
-    ret = svr.compile('test at domain.com', (info, None))
-    assert svr._channel.receive().find('going to send') > -1
+    svr.compile('test at domain.com', (info, None))
+    ret = svr._channel.receive()
+    assert ret.find('going to send') > -1
     assert c2.channel.receive() == 'bar: [3]'
     assert c2.channel.receive() is None
     py.test.raises(IndexError, "c1.channel.receive()")
@@ -78,10 +83,13 @@
     assert ret[0]
     assert isinstance(ret[1], str)
     assert BuildPath(ret[1]) == bp
-    assert svr._channel.receive().find('compilation done for') > -1
+    ret = svr._channel.receive()
+    assert ret.find('compilation done for') > -1
     for i in range(2):
-        assert svr._channel.receive().find('going to send email to') > -1
-    assert svr._channel.receive().find('already a build for this info') > -1
+        ret = svr._channel.receive()
+        assert ret.find('going to send email to') > -1
+    ret = svr._channel.receive()
+    assert ret.find('already a build for this info') > -1
     
 def test_buildpath():
     tempdir = py.test.ensuretemp('pypybuilder-buildpath')



More information about the Pypy-commit mailing list