[z3-checkins] r21942 - z3/sqlos/trunk/src/sqlos/ftests
jinty at codespeak.net
jinty at codespeak.net
Wed Jan 11 15:17:30 CET 2006
Author: jinty
Date: Wed Jan 11 15:17:26 2006
New Revision: 21942
Added:
z3/sqlos/trunk/src/sqlos/ftests/connection.txt (contents, props changed)
Modified:
z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py
Log:
A small functional test for a part of the connection logic.
Added: z3/sqlos/trunk/src/sqlos/ftests/connection.txt
==============================================================================
--- (empty file)
+++ z3/sqlos/trunk/src/sqlos/ftests/connection.txt Wed Jan 11 15:17:26 2006
@@ -0,0 +1,40 @@
+Here we test how the connections work with threading
+
+ >>> from sqlos.connection import getConnection, releaseConnection
+ >>> from sqlos.interfaces import IConnectionName
+ >>> from zope.app import zapi
+
+Get the connection name defined in sqlos:
+
+ >>> ut = zapi.getUtility(IConnectionName)
+
+Make sure that the connections are released:
+
+ >>> releaseConnection(ut.name)
+
+Assert that if we get a connection twice, we get the same connection:
+
+ >>> conn1 = getConnection(None, ut.name)
+ >>> conn2 = getConnection(None, ut.name)
+ >>> conn1 is conn2
+ True
+
+But getting a connection in a different thread returns a different result:
+
+ >>> log = []
+ >>> def f():
+ ... conn = getConnection(None, ut.name)
+ ... log.append(conn)
+ >>> import threading
+ >>> thread = threading.Thread(target=f)
+ >>> thread.start()
+ >>> thread.join()
+ >>> log[0] is not conn1
+ True
+
+Releasing a connection will release it from the current thread:
+
+ >>> releaseConnection(ut.name)
+ >>> conn = getConnection(None, ut.name)
+ >>> conn is not conn1
+ True
Modified: z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py
==============================================================================
--- z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py (original)
+++ z3/sqlos/trunk/src/sqlos/ftests/test_doctest.py Wed Jan 11 15:17:26 2006
@@ -7,6 +7,7 @@
def test_suite():
filelist = [readme,
'adding.txt',
+ 'connection.txt',
'containers.txt',
# localutilities test is disabled as it is broken
# 'localutilities.txt',
More information about the z3-checkins
mailing list