Re: [Zope3-dev] Phantom of GadflyAdapter

2006-01-03 Thread Stephan Richter
On Wednesday 14 December 2005 04:06, Tadashi Matsumoto wrote:
 I have made a test. It works well (perhaps).
 This test program is small, so I have attached in this mail.

Thank you very much. See revision 41109.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Phantom of GadflyAdapter

2005-12-14 Thread Tadashi Matsumoto
On Tue, 13 Dec 2005 10:08:17 -0500
[EMAIL PROTECTED] wrote.

 On Tuesday 13 December 2005 09:54, Tadashi Matsumoto wrote:

 If you write a test for this, I'll check it in.
 

I have made a test. It works well (perhaps).
This test program is small, so I have attached in this mail.


Tadashi Matsumoto
[EMAIL PROTECTED]
import os, shutil
import tempfile, threading
from unittest import TestCase, TestSuite, main, makeSuite

from zope.app.rdb.gadflyda import GadflyAdapter, setGadflyRoot

class GadflyTestBase(TestCase):

def setUp(self):
TestCase.setUp(self)
self.tempdir = None

def tearDown(self):
TestCase.tearDown(self)
if self.tempdir:
shutil.rmtree(self.tempdir)
setGadflyRoot()

def getGadflyRoot(self):
if not self.tempdir:
self.tempdir = tempfile.mkdtemp('gadfly')
setGadflyRoot(self.tempdir)
return self.tempdir

def _create(self, *args):
return GadflyAdapter(*args)

def exec_sql(adapter, sql, args, fetch=False):

conn = adapter()
cur =conn.cursor()
cur.execute(sql, args)
rows = []
if fetch:
rows = cur.fetchall()
conn.commit()
return rows

class TestPhantom(GadflyTestBase):

def setUp(self):
GadflyTestBase.setUp(self)
dir = self.getGadflyRoot()
os.mkdir(os.path.join(dir, demo))
self.adapter = self._create(dbi://demo)
conn = self.adapter()
cur = conn.cursor()
cur.execute(create table t1 (name varchar))
conn.commit()

def test_Phantom(self):

adapter = self.adapter
insert = insert into t1 values (?)
select = select name from t1
delete = delete from t1

count = 0
for name in ('a', 'b', 'c'):
t = threading.Thread(target=exec_sql,
 args=(adapter, insert, (name,)))
t.start()
t.join()
rows = exec_sql(adapter, select, args=(), fetch=True)
count += 1 
self.assertEqual(len(rows), count)

exec_sql(adapter, delete, args=())
t = threading.Thread(target=exec_sql,
 args=(adapter, delete, ()))
t.start()
t.join()
rows = exec_sql(adapter, select, args=(), fetch=True)
self.assertEqual(len(rows), 0) 

def test_suite():
return TestSuite((
makeSuite(TestPhantom),
))

if __name__=='__main__':

main(defaultTest='test_suite')
  ___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Phantom of GadflyAdapter

2005-12-13 Thread Tadashi Matsumoto
Phantom of GadflyAdapter

GadflyAdapter sometimes causes phantom read.

The reason is that many connections are made simultaneously
on a gadfly database through the thead local variable
_v_connection. Threadsafety level 2 or higher is required
to use the thread local variable.

To remedy this fault, it is enough to use
usual variable as _v_connection. But users need to control
lock/unlock of the connection by themselves.

Simple patch:

--- gadflyda.py.org 2005-12-06 22:19:47.0 +0900
+++ gadflyda.py 2005-12-12 22:41:07.0 +0900
@@ -51,6 +51,8 @@
 
 # The registerable object needs to have a container
 __name__ = __parent__ = None 
+_v_connection = None
+paramstyle = 'qmark'
 
 def _connection_factory(self):
 Create a Gadfly DBI connection based on the DSN.


Tadashi Matsumoto
[EMAIL PROTECTED]
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Phantom of GadflyAdapter

2005-12-13 Thread Stephan Richter
On Tuesday 13 December 2005 09:54, Tadashi Matsumoto wrote:
 Simple patch:

 --- gadflyda.py.org     2005-12-06 22:19:47.0 +0900
 +++ gadflyda.py 2005-12-12 22:41:07.0 +0900
 @@ -51,6 +51,8 @@
  
      # The registerable object needs to have a container
      __name__ = __parent__ = None
 +    _v_connection = None
 +    paramstyle = 'qmark'
  
      def _connection_factory(self):
          Create a Gadfly DBI connection based on the DSN.

If you write a test for this, I'll check it in.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics  Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Phantom of GadflyAdapter

2005-12-13 Thread Tadashi Matsumoto
On Tue, 13 Dec 2005 10:08:17 -0500
[EMAIL PROTECTED] wrote.

 On Tuesday 13 December 2005 09:54, Tadashi Matsumoto wrote:
  Simple patch:
 
 If you write a test for this, I'll check it in.
 

Ok, I will try.
But I'm not sure I can make a test that always fails
for the origial code and succeeds for the patched one.



Tadashi Matsumoto
[EMAIL PROTECTED]
___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com