Merge lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset into lp:txlongpoll

Proposed by Free Ekanayaka
Status: Merged
Merged at revision: 90
Proposed branch: lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset
Merge into: lp:txlongpoll
Diff against target: 145 lines (+51/-15)
6 files modified
.testr.conf (+1/-2)
README (+1/-1)
buildout.cfg (+6/-0)
txlongpoll/testing/client.py (+25/-10)
txlongpoll/tests/__init__.py (+13/-0)
txlongpoll/tests/test_frontend.py (+5/-2)
To merge this branch: bzr merge lp:~free.ekanayaka/txlongpoll/fast-rabbit-reset
Reviewer Review Type Date Requested Status
William Grant code Needs Fixing
Robert Collins (community) Needs Fixing
Review via email: mp+278287@code.launchpad.net

Description of the change

This branch adds a few improvements to the test suite:

- Take advantage of testresources.OptimisingTestSuite in order to avoid a wholesale shutdown/restart of the rabbit process at each test and just delete the queues created by the test instead.

- Silence the Twisted logger in FrontEndAjaxTest.test_render_error.

- Remove the workaround of aborting tearDown early without running any asynchronous logic (see the comment in the code).

- Point buildout to bson 0.4.3 since the default (1.1.1) is not compatible
with Python 2.

To post a comment you must log in.
90. By Free Ekanayaka

Add custom test program

91. By Free Ekanayaka

Revert spurious changes

Revision history for this message
Robert Collins (lifeless) wrote :

The whole custom runner is not needed, is it? Why is it there. Surely a load_tests hook is much cleaner.

review: Needs Fixing
92. By Free Ekanayaka

Use load_tests protocol

93. By Free Ekanayaka

Fix buildout versions

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

> The whole custom runner is not needed, is it? Why is it there. Surely a
> load_tests hook is much cleaner.

Nice, didn't know about it. Fixed as suggested.

Revision history for this message
Robert Collins (lifeless) :
Revision history for this message
Free Ekanayaka (free.ekanayaka) :
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
William Grant (wgrant) wrote :

The new load_tests doesn't seem to work as intended (on at least precise and xenial). If I break at the end and inspect result:

(Pdb) p result
<testresources.OptimisingTestSuite tests=[<unittest2.suite.TestSuite tests=[<unittest2.suite.TestSuite tests=[<txlongpoll.tests.test_client.AMQClosingTest.test_catch_closed [...]

It's an OptimisingTestSuite wrapping a whole lot of normal TestSuites, so the fixture is restarted for each test, and the newly un-neutered tearDown fails.

Overriding loader.suiteClass works, but I wonder if there is a better way.

review: Needs Fixing (code)
94. By Free Ekanayaka

Fix testr configuration

Revision history for this message
William Grant (wgrant) wrote :

As discussed on IRC, the problem was my old version of testresources. Newer versions of OptimisingTestSuite flatten nested test suites, fixing the problem.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.testr.conf'
2--- .testr.conf 2011-11-08 11:30:22 +0000
3+++ .testr.conf 2016-05-25 08:37:19 +0000
4@@ -1,5 +1,4 @@
5 [DEFAULT]
6 test_command = bin/testpy -m subunit/run -- discover $LISTOPT $IDOPTION
7 test_id_option = --load-list $IDFILE
8-# The "ignore" value below works around a bug in subunit.
9-test_list_option = --list=ignore
10+test_list_option = --list
11
12=== modified file 'README'
13--- README 2011-11-08 11:30:22 +0000
14+++ README 2016-05-25 08:37:19 +0000
15@@ -42,7 +42,7 @@
16 will build all the test-related parts of txlongpoll and then do a full
17 test run, but
18
19- $ make bin/test
20+ $ make bin/testpy
21
22 will just do the first part.
23
24
25=== modified file 'buildout.cfg'
26--- buildout.cfg 2012-03-12 17:07:58 +0000
27+++ buildout.cfg 2016-05-25 08:37:19 +0000
28@@ -18,6 +18,12 @@
29 # Once you have the desired software, reenable this option.
30 install-from-cache = true
31
32+[versions]
33+# Set the version explicitely for bson, since the default would be
34+# version 1.1.1 which is not compatible with Python 2.
35+# See https://pypi.python.org/pypi/bson/1.1.0
36+bson = 0.4.3
37+
38 [runtime]
39 recipe = zc.recipe.egg:scripts
40 eggs = txlongpoll
41
42=== modified file 'txlongpoll/testing/client.py'
43--- txlongpoll/testing/client.py 2011-09-30 09:56:12 +0000
44+++ txlongpoll/testing/client.py 2016-05-25 08:37:19 +0000
45@@ -36,12 +36,22 @@
46 return self._real_queue_get(timeout)
47
48
49+class RabbitServerWithoutReset(RabbitServer):
50+
51+ def reset(self):
52+ """No-op reset.
53+
54+ Logic to cleanup relevant state is delegated to the test case, which is
55+ in charge to delete the queues it created (see AMQTest.tearDown).
56+ """
57+
58+
59 class AMQTest(ResourcedTestCase, TestCase):
60
61 run_tests_with = AsynchronousDeferredRunTestForBrokenTwisted.make_factory(
62 timeout=5)
63
64- resources = [('rabbit', FixtureResource(RabbitServer()))]
65+ resources = [('rabbit', FixtureResource(RabbitServerWithoutReset()))]
66
67 VHOST = "/"
68 USER = "guest"
69@@ -65,18 +75,23 @@
70 self.factory)
71 return self.connected_deferred
72
73+ def tearDown(self):
74+ # The AsynchronousDeferredRunTest machinery from testools doesn't play
75+ # well with an asynchronous tearDown decorated with inlineCallbacks,
76+ # because testtools.TestCase._run_teardown attempts to ensure that the
77+ # test class upcalls testtools.TestCase.tearDown and raises an error if
78+ # it doesn't find it. To workaround that, we move the inlineCallbacks
79+ # logic in a separate method, so we can run the superclass tearDown()
80+ # before returning.
81+ deferred = self._deleteQueuesAndExchanges()
82+ super(AMQTest, self).tearDown()
83+ return deferred
84+
85 @inlineCallbacks
86- def tearDown(self):
87- # XXX: Moving this up here to silence a nigh-on inexplicable error
88- # that occurs when it's at the bottom of the function.
89+ def _deleteQueuesAndExchanges(self):
90+ """Delete any queue or exchange that the test might have created."""
91 self.factory.stopTrying()
92 self.connector.disconnect()
93- super(AMQTest, self).tearDown()
94-
95- # XXX: This is only safe because we tear down the whole server.
96- # We can't run this after the tearDown above, because the
97- # fixture is gone.
98- return
99
100 self.connected_deferred = Deferred()
101 factory = AMQFactory(self.USER, self.PASSWORD, self.VHOST,
102
103=== modified file 'txlongpoll/tests/__init__.py'
104--- txlongpoll/tests/__init__.py 2011-06-28 16:21:03 +0000
105+++ txlongpoll/tests/__init__.py 2016-05-25 08:37:19 +0000
106@@ -1,2 +1,15 @@
107 # Copyright 2005-2011 Canonical Ltd. This software is licensed under the
108 # GNU Affero General Public License version 3 (see the file LICENSE).
109+import os
110+
111+from testresources import OptimisingTestSuite
112+
113+
114+def load_tests(loader, standard_tests, pattern):
115+ # top level directory cached on loader instance
116+ this_dir = os.path.dirname(__file__)
117+ package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
118+ result = OptimisingTestSuite()
119+ result.addTests(standard_tests)
120+ result.addTests(package_tests)
121+ return result
122
123=== modified file 'txlongpoll/tests/test_frontend.py'
124--- txlongpoll/tests/test_frontend.py 2011-09-30 09:56:12 +0000
125+++ txlongpoll/tests/test_frontend.py 2016-05-25 08:37:19 +0000
126@@ -6,7 +6,10 @@
127 from unittest import defaultTestLoader
128
129 from testtools import TestCase
130-from testtools.deferredruntest import assert_fails_with
131+from testtools.deferredruntest import (
132+ assert_fails_with,
133+ run_with_log_observers,
134+ )
135 from twisted.internet import reactor
136 from twisted.internet.defer import (
137 Deferred,
138@@ -374,7 +377,7 @@
139 """
140 self.message_queue.messages["uuid1"] = ValueError("Not there")
141 request = FakeRequest({"uuid": ["uuid1"], "sequence": ["0"]})
142- self.ajax.render(request)
143+ run_with_log_observers([], self.ajax.render, request)
144 self.assertEquals(request.written.getvalue(), "Not there")
145 self.assertEquals(request.code, 500)
146

Subscribers

People subscribed via source and target branches