Commit bb2396cd authored by Jim Fulton's avatar Jim Fulton

Make mutating thread daemonic and stop it if there is an error in the

test thread.

Use with to simplify locking code.
parent d8eca66b
...@@ -50,14 +50,12 @@ This tests tries to provoke this bug by: ...@@ -50,14 +50,12 @@ This tests tries to provoke this bug by:
... i = random.randint(0, nobs-1) ... i = random.randint(0, nobs-1)
... if stop: ... if stop:
... return ... return
... lock.acquire() ... with lock:
... try:
... conn2.root()[i].value += 1 ... conn2.root()[i].value += 1
... tm.commit() ... tm.commit()
... finally:
... lock.release()
... time.sleep(0) ... time.sleep(0)
>>> thread = threading.Thread(target=run) >>> thread = threading.Thread(target=run)
>>> thread.setDaemon(True)
>>> thread.start() >>> thread.start()
- restarting the first client, and - restarting the first client, and
...@@ -67,14 +65,14 @@ This tests tries to provoke this bug by: ...@@ -67,14 +65,14 @@ This tests tries to provoke this bug by:
>>> handler = zope.testing.loggingsupport.InstalledHandler( >>> handler = zope.testing.loggingsupport.InstalledHandler(
... 'ZEO', level=logging.ERROR) ... 'ZEO', level=logging.ERROR)
>>> for c in range(10): >>> try:
... for c in range(10):
... time.sleep(.1) ... time.sleep(.1)
... db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x')) ... db = ZODB.DB(ZEO.ClientStorage.ClientStorage(addr, client='x'))
... _ = lock.acquire() ... with lock:
... try: ... @wait_until("connected and we've caught up", timeout=199)
... wait_until("connected and we've caught up", ... def _():
... lambda : ... return (db.storage.is_connected()
... db.storage.is_connected()
... and db.storage.lastTransaction() ... and db.storage.lastTransaction()
... == db.storage._server.lastTransaction() ... == db.storage._server.lastTransaction()
... ) ... )
...@@ -84,12 +82,11 @@ This tests tries to provoke this bug by: ...@@ -84,12 +82,11 @@ This tests tries to provoke this bug by:
... if conn.root()[i].value != conn2.root()[i].value: ... if conn.root()[i].value != conn2.root()[i].value:
... print 'bad', c, i, conn.root()[i].value, ... print 'bad', c, i, conn.root()[i].value,
... print conn2.root()[i].value ... print conn2.root()[i].value
... finally:
... _ = lock.release()
... db.close() ... db.close()
... finally:
... stop = True
... thread.join(10)
>>> stop = True
>>> thread.join(10)
>>> thread.isAlive() >>> thread.isAlive()
False False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment