[Checkins] SVN: zc.zk/trunk/src/zc/zk/ Moved a test dealing with a connection edge case from a test text file
Jim Fulton
jim at zope.com
Fri Jan 6 17:20:45 UTC 2012
Log message for revision 123969:
Moved a test dealing with a connection edge case from a test text file
to a Python module which will collect other small edge cases.
Changed:
A zc.zk/trunk/src/zc/zk/disconnectiontests.py
U zc.zk/trunk/src/zc/zk/tests.py
D zc.zk/trunk/src/zc/zk/wait_for_zookeeper.test
-=-
Added: zc.zk/trunk/src/zc/zk/disconnectiontests.py
===================================================================
--- zc.zk/trunk/src/zc/zk/disconnectiontests.py (rev 0)
+++ zc.zk/trunk/src/zc/zk/disconnectiontests.py 2012-01-06 17:20:44 UTC (rev 123969)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# Copyright Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+
+# This module has tests that involve zookeeper being disconnected.
+
+# Their in a separate module to avoid testing with a real zookeeper
+# server, which we can't control (or at least don't want to work hard
+# enough to control).
+
+def wait_for_zookeeper():
+ """
+ Normally, zc.zk.ZooKeeper raises an exception if it can't connect to
+ ZooKeeper in a second. Some applications might want to wait, so
+ zc.zk.ZooKeeper accepts a wait parameter that causes it to wait for a
+ connection.
+
+ >>> zk = None
+ >>> import zc.zk, zc.thread, zookeeper, zope.testing.loggingsupport
+
+ >>> handler = zope.testing.loggingsupport.InstalledHandler('zc.zk')
+
+ >>> @zc.thread.Thread
+ ... def connect():
+ ... global zk
+ ... zk = zc.zk.ZooKeeper('Invalid', wait=True)
+
+ We'll wait a while while it tries in vane to connect:
+
+ >>> wait_until((lambda : zk is not None), 4)
+ Traceback (most recent call last):
+ ...
+ AssertionError: timeout
+
+ >>> print handler # doctest: +ELLIPSIS
+ zc.zk CRITICAL
+ Can't connect to ZooKeeper at 'Invalid'
+ zc.zk CRITICAL
+ Can't connect to ZooKeeper at 'Invalid'
+ ...
+ >>> handler.uninstall()
+
+ Now, we'll make the connection possible:
+
+ >>> ZooKeeper._allow_connection('Invalid')
+ >>> wait_until(lambda : zk is not None)
+
+ >>> zk.state == zookeeper.CONNECTED_STATE
+ True
+
+ Yay!
+
+ >>> zk.close()
+ """
+
Property changes on: zc.zk/trunk/src/zc/zk/disconnectiontests.py
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: zc.zk/trunk/src/zc/zk/tests.py
===================================================================
--- zc.zk/trunk/src/zc/zk/tests.py 2012-01-06 15:10:28 UTC (rev 123968)
+++ zc.zk/trunk/src/zc/zk/tests.py 2012-01-06 17:20:44 UTC (rev 123969)
@@ -1325,9 +1325,14 @@
suite.addTest(unittest.makeSuite(LoggingTests))
suite.addTest(doctest.DocFileSuite(
'ephemeral_node_recovery_on_session_reestablishment.test',
- 'wait_for_zookeeper.test',
setUp=setUpEphemeral_node_recovery_on_session_reestablishment,
tearDown=zc.zk.testing.tearDown,
checker=checker,
))
+ suite.addTest(doctest.DocTestSuite(
+ 'zc.zk.disconnectiontests',
+ setUp=zc.zk.testing.setUp, tearDown=zc.zk.testing.tearDown,
+ checker=checker,
+ ))
+
return suite
Deleted: zc.zk/trunk/src/zc/zk/wait_for_zookeeper.test
===================================================================
--- zc.zk/trunk/src/zc/zk/wait_for_zookeeper.test 2012-01-06 15:10:28 UTC (rev 123968)
+++ zc.zk/trunk/src/zc/zk/wait_for_zookeeper.test 2012-01-06 17:20:44 UTC (rev 123969)
@@ -1,41 +0,0 @@
-Normally, zc.zk.ZooKeeper raises an exception if it can't connect to
-ZooKeeper in a second. Some applications might want to wait, so
-zc.zk.ZooKeeper accepts a wait parameter that causes it to wait for a
-connection.
-
- >>> zk = None
- >>> import zc.zk, zc.thread, zookeeper, zope.testing.loggingsupport
-
- >>> handler = zope.testing.loggingsupport.InstalledHandler('zc.zk')
-
- >>> @zc.thread.Thread
- ... def connect():
- ... global zk
- ... zk = zc.zk.ZooKeeper('Invalid', wait=True)
-
-We'll wait a while while it tries in vane to connect:
-
- >>> wait_until((lambda : zk is not None), 4)
- Traceback (most recent call last):
- ...
- AssertionError: timeout
-
- >>> print handler # doctest: +ELLIPSIS
- zc.zk CRITICAL
- Can't connect to ZooKeeper at 'Invalid'
- zc.zk CRITICAL
- Can't connect to ZooKeeper at 'Invalid'
- ...
- >>> handler.uninstall()
-
-Now, we'll make the connection possible:
-
- >>> ZooKeeper._allow_connection('Invalid')
- >>> wait_until(lambda : zk is not None)
-
- >>> zk.state == zookeeper.CONNECTED_STATE
- True
-
-Yay!
-
- >>> zk.close()
More information about the checkins
mailing list