[Zodb-checkins] CVS: StandaloneZODB/ZEO/tests - testTransactionBuffer.py:1.2 forker.py:1.11
Jeremy Hylton
jeremy@zope.com
Fri, 11 Jan 2002 14:29:51 -0500
Update of /cvs-repository/StandaloneZODB/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv29427
Modified Files:
forker.py
Added Files:
testTransactionBuffer.py
Log Message:
Changes from the ZEO-ZRPC-Dev branch merge.
=== StandaloneZODB/ZEO/tests/testTransactionBuffer.py 1.1 => 1.2 ===
+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 => 1.11 ===
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 1.1 (ZPL). A copy of the ZPL should accompany this
+# distribution. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL
+# EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST
+# INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
+
"""Library for forking storage server and connecting client storage"""
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.
@@ -66,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:
@@ -77,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)
@@ -98,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)
@@ -128,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