[Zodb-checkins] CVS: StandaloneZODB/ZEO/tests - testTransactionBuffer.py:1.3.2.1 forker.py:1.10.4.3

Jeremy Hylton jeremy@zope.com
Fri, 11 Jan 2002 15:25:10 -0500


Update of /cvs-repository/StandaloneZODB/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv10361

Modified Files:
      Tag: Standby-branch
	forker.py 
Added Files:
      Tag: Standby-branch
	testTransactionBuffer.py 
Log Message:
Merge ZEO-ZRPC-Dev branch into Standby-branch.



=== Added File StandaloneZODB/ZEO/tests/testTransactionBuffer.py ===
import random
import unittest

from ZEO.TransactionBuffer import TransactionBuffer

def random_string(size):
    """Return a random string of size size."""
    l = [chr(random.randrange(256)) for i in range(size)]
    return "".join(l)

def new_store_data():
    """Return arbitrary data to use as argument to store() method."""
    return random_string(8), '', random_string(random.randrange(1000))

def new_invalidate_data():
    """Return arbitrary data to use as argument to invalidate() method."""
    return random_string(8), ''

class TransBufTests(unittest.TestCase):

    def checkTypicalUsage(self):
        tbuf = TransactionBuffer()
        tbuf.store(*new_store_data())
        tbuf.invalidate(*new_invalidate_data())
        tbuf.begin_iterate()
        while 1:
            o = tbuf.next()
            if o is None:
                break
        tbuf.clear()

    def doUpdates(self, tbuf):
        data = []
        for i in range(10):
            d = new_store_data()
            tbuf.store(*d)
            data.append(d)
            d = new_invalidate_data()
            tbuf.invalidate(*d)
            data.append(d)

        tbuf.begin_iterate()
        for i in range(len(data)):
            x = tbuf.next()
            if x[2] is None:
                # the tbuf add a dummy None to invalidates
                x = x[:2]
            self.assertEqual(x, data[i])
        
    def checkOrderPreserved(self):
        tbuf = TransactionBuffer()
        self.doUpdates(tbuf)

    def checkReusable(self):
        tbuf = TransactionBuffer()
        self.doUpdates(tbuf)
        tbuf.clear()
        self.doUpdates(tbuf)
        tbuf.clear()
        self.doUpdates(tbuf)

def test_suite():
    return unittest.makeSuite(TransBufTests, 'check')



=== StandaloneZODB/ZEO/tests/forker.py 1.10.4.2 => 1.10.4.3 ===
 import asyncore
 import os
-import profile
 import random
 import socket
 import sys
+import traceback
 import types
 import ZEO.ClientStorage, ZEO.StorageServer
 
+# Change value of PROFILE to enable server-side profiling
 PROFILE = 0
+if PROFILE:
+    import hotshot
 
 def get_port():
     """Return a port that is not in use.
@@ -57,7 +60,7 @@
         args = (sys.executable, script, str(port), storage_name) + args
         d = os.environ.copy()
         d['PYTHONPATH'] = os.pathsep.join(sys.path)
-        pid = os.spawnve(os.P_NOWAIT, sys.executable, args, d)
+        pid = os.spawnve(os.P_NOWAIT, sys.executable, args, os.environ)
         return ('localhost', port), ('localhost', port + 1), pid
 
 else:
@@ -75,9 +78,11 @@
             buf = self.recv(4)
             if buf:
                 assert buf == "done"
+                server.close_server()
                 asyncore.socket_map.clear()
 
         def handle_close(self):
+            server.close_server()
             asyncore.socket_map.clear()
 
     class ZEOClientExit:
@@ -86,20 +91,27 @@
             self.pipe = pipe
 
         def close(self):
-            os.write(self.pipe, "done")
-            os.close(self.pipe)
+            try:
+                os.write(self.pipe, "done")
+                os.close(self.pipe)
+            except os.error:
+                pass
 
     def start_zeo_server(storage, addr):
         rd, wr = os.pipe()
         pid = os.fork()
         if pid == 0:
-            if PROFILE:
-                p = profile.Profile()
-                p.runctx("run_server(storage, addr, rd, wr)", globals(),
-                         locals())
-                p.dump_stats("stats.s.%d" % os.getpid())
-            else:
-                run_server(storage, addr, rd, wr)
+            try:
+                if PROFILE:
+                    p = hotshot.Profile("stats.s.%d" % os.getpid())
+                    p.runctx("run_server(storage, addr, rd, wr)",
+                             globals(), locals())
+                    p.close()
+                else:
+                    run_server(storage, addr, rd, wr)
+            except:
+                print "Exception in ZEO server process"
+                traceback.print_exc()
             os._exit(0)
         else:
             os.close(rd)
@@ -107,11 +119,11 @@
 
     def run_server(storage, addr, rd, wr):
         # in the child, run the storage server
+        global server
         os.close(wr)
         ZEOServerExit(rd)
-        serv = ZEO.StorageServer.StorageServer(addr, {'1':storage})
+        server = ZEO.StorageServer.StorageServer(addr, {'1':storage})
         asyncore.loop()
-        os.close(rd)
         storage.close()
         if isinstance(addr, types.StringType):
             os.unlink(addr)
@@ -137,6 +149,7 @@
         s = ZEO.ClientStorage.ClientStorage(addr, storage_id,
                                             debug=1, client=cache,
                                             cache_size=cache_size,
-                                            min_disconnect_poll=0.5)
+                                            min_disconnect_poll=0.5,
+                                            wait_for_server_on_startup=1)
         return s, exit, pid