[CalendarServer-changes] [6826] CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 28 17:39:35 PST 2011
Revision: 6826
http://trac.macosforge.org/projects/calendarserver/changeset/6826
Author: glyph at apple.com
Date: 2011-01-28 17:39:35 -0800 (Fri, 28 Jan 2011)
Log Message:
-----------
improve the test a little more
Modified Paths:
--------------
CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py
CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py
Modified: CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py 2011-01-29 01:39:23 UTC (rev 6825)
+++ CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/adbapi2.py 2011-01-29 01:39:35 UTC (rev 6826)
@@ -1,4 +1,4 @@
-# -*- test-case-name: twext.enterprise.test. -*-
+# -*- test-case-name: twext.enterprise.test.test_adbapi2 -*-
##
# Copyright (c) 2010 Apple Inc. All rights reserved.
#
@@ -69,10 +69,6 @@
paramstyle = DEFAULT_PARAM_STYLE
def __init__(self, connectionFactory, threadHolder):
- """
- @param connectionFactory: A 0-argument callable which returns a DB-API
- 2.0 connection.
- """
self._completed = False
self._cursor = None
self._holder = threadHolder
@@ -129,6 +125,8 @@
if not self._completed:
self._completed = True
def reallyCommit():
+ if self._cursor is None:
+ return
self._connection.commit()
result = self._holder.submit(reallyCommit)
return result
@@ -140,6 +138,8 @@
if not self._completed:
self._completed = True
def reallyAbort():
+ if self._cursor is None:
+ return
self._connection.rollback()
result = self._holder.submit(reallyAbort)
return result
@@ -174,7 +174,11 @@
self._stopped = True
holder = self._holder
self._holder = None
- holder.submit(self._connection.close)
+ def _reallyClose():
+ if self._cursor is None:
+ return
+ self._connection.close()
+ holder.submit(_reallyClose)
return holder.stop()
@@ -313,9 +317,18 @@
than this many concurrent connections to the database.
@type maxConnections: C{int}
+
+ @ivar reactor: The reactor used for scheduling threads as well as retries
+ for failed connect() attempts.
+
+ @type reactor: L{IReactorTime} and L{IReactorThreads} provider.
"""
+ reactor = _reactor
+ RETRY_TIMEOUT = 10.0
+
+
def __init__(self, connectionFactory, maxConnections=10):
super(ConnectionPool, self).__init__()
self.free = []
@@ -353,7 +366,7 @@
"""
Create a L{ThreadHolder}. (Test hook.)
"""
- return ThreadHolder(_reactor)
+ return ThreadHolder(self.reactor)
def connection(self, label="<unlabeled>"):
@@ -363,7 +376,7 @@
@return: an L{IAsyncTransaction}
"""
- overload = False
+ tracking = self.busy
if self.free:
basetxn = self.free.pop(0)
elif len(self.busy) < self.maxConnections:
@@ -373,12 +386,9 @@
)
else:
basetxn = SpooledTxn()
- overload = True
+ tracking = self.waiting
txn = PooledSqlTxn(self, basetxn)
- if overload:
- self.waiting.append(txn)
- else:
- self.busy.append(txn)
+ tracking.append(txn)
return txn
Modified: CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py 2011-01-29 01:39:23 UTC (rev 6825)
+++ CalendarServer/branches/users/glyph/db-reconnect/twext/enterprise/test/test_adbapi2.py 2011-01-29 01:39:35 UTC (rev 6826)
@@ -25,6 +25,8 @@
from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import execute
+from twisted.internet.task import Clock
+
from twext.enterprise.adbapi2 import ConnectionPool
@@ -227,6 +229,7 @@
self.factory = ConnectionFactory()
self.pool = ConnectionPool(self.factory.connect, maxConnections=2)
self.pool._createHolder = self.makeAHolder
+ self.clock = self.pool.reactor = Clock()
self.pool.startService()
self.addCleanup(self.pool.stopService)
@@ -303,13 +306,25 @@
exception, the L{ConnectionPool} will log the exception and delay
execution of a new connection's SQL methods until an attempt succeeds.
"""
- self.factory.defaultFail()
+ self.factory.willFail()
+ self.factory.willFail()
+ self.factory.willConnect()
c = self.pool.connection()
- errors = self.flushLoggedErrors(FakeConnectionError)
- self.assertEquals(len(errors), 1)
+ def checkOneFailure():
+ errors = self.flushLoggedErrors(FakeConnectionError)
+ self.assertEquals(len(errors), 1)
+ checkOneFailure()
d = c.execSQL("alpha")
happened = []
d.addBoth(happened.append)
self.assertEquals(happened, [])
+ self.clock.advance(self.pool.RETRY_TIMEOUT)
+ checkOneFailure()
+ self.assertEquals(happened, [])
+ self.clock.advance(self.pool.RETRY_TIMEOUT)
+ checkOneFailure()
+ self.assertEquals(happened, [])
+ self.clock.advance(self.pool.RETRY_TIMEOUT)
+ self.assertEquals(happened, [[1, "alpha"]])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110128/12c95c62/attachment.html>
More information about the calendarserver-changes
mailing list