Merge lp:~lifeless/bzr/test-speed into lp:~bzr/bzr/trunk-old
- test-speed
- Merge into trunk-old
Proposed by
Robert Collins
Status: | Merged |
---|---|
Merge reported by: | Robert Collins |
Merged at revision: | not available |
Proposed branch: | lp:~lifeless/bzr/test-speed |
Merge into: | lp:~bzr/bzr/trunk-old |
Diff against target: | 332 lines |
To merge this branch: | bzr merge lp:~lifeless/bzr/test-speed |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Pool | Approve | ||
Review via email:
|
This proposal supersedes a proposal from 2009-08-23.
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Martin Pool (mbp) wrote : Posted in a previous version of this proposal | # |
I think those upper-layer tests are almost pointless, but fixing the lower layers to work on smaller data is certainly welcome.
review:
Approve
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robert Collins (lifeless) wrote : | # |
I ended up doing a couple more things while I was there.
< 10 seconds for the selftest tests now.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Martin Pool (mbp) wrote : | # |
> I ended up doing a couple more things while I was there.
> < 10 seconds for the selftest tests now.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bzrlib/tests/__init__.py' | |||
2 | --- bzrlib/tests/__init__.py 2009-08-20 05:05:59 +0000 | |||
3 | +++ bzrlib/tests/__init__.py 2009-08-24 05:35:11 +0000 | |||
4 | @@ -3207,6 +3207,7 @@ | |||
5 | 3207 | starting_with=None, | 3207 | starting_with=None, |
6 | 3208 | runner_class=None, | 3208 | runner_class=None, |
7 | 3209 | suite_decorators=None, | 3209 | suite_decorators=None, |
8 | 3210 | stream=None, | ||
9 | 3210 | ): | 3211 | ): |
10 | 3211 | """Run the whole test suite under the enhanced runner""" | 3212 | """Run the whole test suite under the enhanced runner""" |
11 | 3212 | # XXX: Very ugly way to do this... | 3213 | # XXX: Very ugly way to do this... |
12 | @@ -3245,6 +3246,7 @@ | |||
13 | 3245 | strict=strict, | 3246 | strict=strict, |
14 | 3246 | runner_class=runner_class, | 3247 | runner_class=runner_class, |
15 | 3247 | suite_decorators=suite_decorators, | 3248 | suite_decorators=suite_decorators, |
16 | 3249 | stream=stream, | ||
17 | 3248 | ) | 3250 | ) |
18 | 3249 | finally: | 3251 | finally: |
19 | 3250 | default_transport = old_transport | 3252 | default_transport = old_transport |
20 | 3251 | 3253 | ||
21 | === modified file 'bzrlib/tests/blackbox/test_selftest.py' | |||
22 | --- bzrlib/tests/blackbox/test_selftest.py 2009-07-10 07:14:02 +0000 | |||
23 | +++ bzrlib/tests/blackbox/test_selftest.py 2009-08-24 05:35:11 +0000 | |||
24 | @@ -26,6 +26,7 @@ | |||
25 | 26 | import bzrlib | 26 | import bzrlib |
26 | 27 | from bzrlib import ( | 27 | from bzrlib import ( |
27 | 28 | osutils, | 28 | osutils, |
28 | 29 | tests, | ||
29 | 29 | ) | 30 | ) |
30 | 30 | from bzrlib.errors import ParamikoNotPresent | 31 | from bzrlib.errors import ParamikoNotPresent |
31 | 31 | from bzrlib.tests import ( | 32 | from bzrlib.tests import ( |
32 | @@ -42,67 +43,59 @@ | |||
33 | 42 | 43 | ||
34 | 43 | class TestOptions(TestCase): | 44 | class TestOptions(TestCase): |
35 | 44 | 45 | ||
36 | 45 | current_test = None | ||
37 | 46 | |||
38 | 47 | def test_transport_set_to_sftp(self): | 46 | def test_transport_set_to_sftp(self): |
41 | 48 | # test the --transport option has taken effect from within the | 47 | # Test that we can pass a transport to the selftest core - sftp |
42 | 49 | # test_transport test | 48 | # version. |
43 | 50 | try: | 49 | try: |
44 | 51 | import bzrlib.transport.sftp | 50 | import bzrlib.transport.sftp |
45 | 52 | except ParamikoNotPresent: | 51 | except ParamikoNotPresent: |
46 | 53 | raise TestSkipped("Paramiko not present") | 52 | raise TestSkipped("Paramiko not present") |
49 | 54 | if TestOptions.current_test != "test_transport_set_to_sftp": | 53 | params = self.get_params_passed_to_core('selftest --transport=sftp') |
48 | 55 | return | ||
50 | 56 | self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer, | 54 | self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer, |
52 | 57 | bzrlib.tests.default_transport) | 55 | params[1]["transport"]) |
53 | 58 | 56 | ||
54 | 59 | def test_transport_set_to_memory(self): | 57 | def test_transport_set_to_memory(self): |
57 | 60 | # test the --transport option has taken effect from within the | 58 | # Test that we can pass a transport to the selftest core - memory |
58 | 61 | # test_transport test | 59 | # version. |
59 | 62 | import bzrlib.transport.memory | 60 | import bzrlib.transport.memory |
62 | 63 | if TestOptions.current_test != "test_transport_set_to_memory": | 61 | params = self.get_params_passed_to_core('selftest --transport=memory') |
61 | 64 | return | ||
63 | 65 | self.assertEqual(bzrlib.transport.memory.MemoryServer, | 62 | self.assertEqual(bzrlib.transport.memory.MemoryServer, |
87 | 66 | bzrlib.tests.default_transport) | 63 | params[1]["transport"]) |
88 | 67 | 64 | ||
89 | 68 | def test_transport(self): | 65 | def get_params_passed_to_core(self, cmdline): |
90 | 69 | # test that --transport=sftp works | 66 | params = [] |
91 | 70 | try: | 67 | def selftest(*args, **kwargs): |
92 | 71 | import bzrlib.transport.sftp | 68 | """Capture the arguments selftest was run with.""" |
93 | 72 | except ParamikoNotPresent: | 69 | params.append((args, kwargs)) |
94 | 73 | raise TestSkipped("Paramiko not present") | 70 | return True |
95 | 74 | old_transport = bzrlib.tests.default_transport | 71 | # Yes this prevents using threads to run the test suite in parallel, |
96 | 75 | old_root = TestCaseWithMemoryTransport.TEST_ROOT | 72 | # however we don't have a clean dependency injector for commands, |
97 | 76 | TestCaseWithMemoryTransport.TEST_ROOT = None | 73 | # and even if we did - we'd still be testing that the glue is wired |
98 | 77 | try: | 74 | # up correctly. XXX: TODO: Solve this testing problem. |
99 | 78 | TestOptions.current_test = "test_transport_set_to_sftp" | 75 | original_selftest = tests.selftest |
100 | 79 | stdout = self.run_bzr( | 76 | tests.selftest = selftest |
101 | 80 | 'selftest --transport=sftp test_transport_set_to_sftp')[0] | 77 | try: |
102 | 81 | self.assertContainsRe(stdout, 'Ran 1 test') | 78 | self.run_bzr(cmdline) |
103 | 82 | self.assertEqual(old_transport, bzrlib.tests.default_transport) | 79 | return params[0] |
81 | 83 | |||
82 | 84 | TestOptions.current_test = "test_transport_set_to_memory" | ||
83 | 85 | stdout = self.run_bzr( | ||
84 | 86 | 'selftest --transport=memory test_transport_set_to_memory')[0] | ||
85 | 87 | self.assertContainsRe(stdout, 'Ran 1 test') | ||
86 | 88 | self.assertEqual(old_transport, bzrlib.tests.default_transport) | ||
104 | 89 | finally: | 80 | finally: |
108 | 90 | bzrlib.tests.default_transport = old_transport | 81 | tests.selftest = original_selftest |
109 | 91 | TestOptions.current_test = None | 82 | |
110 | 92 | TestCaseWithMemoryTransport.TEST_ROOT = old_root | 83 | def test_parameters_passed_to_core(self): |
111 | 84 | params = self.get_params_passed_to_core('selftest --list-only') | ||
112 | 85 | self.assertTrue("list_only" in params[1]) | ||
113 | 86 | params = self.get_params_passed_to_core('selftest --list-only selftest') | ||
114 | 87 | self.assertTrue("list_only" in params[1]) | ||
115 | 88 | params = self.get_params_passed_to_core(['selftest', '--list-only', | ||
116 | 89 | '--exclude', 'selftest']) | ||
117 | 90 | self.assertTrue("list_only" in params[1]) | ||
118 | 91 | params = self.get_params_passed_to_core(['selftest', '--list-only', | ||
119 | 92 | 'selftest', '--randomize', 'now']) | ||
120 | 93 | self.assertSubset(["list_only", "random_seed"], params[1]) | ||
121 | 93 | 94 | ||
122 | 94 | def test_subunit(self): | 95 | def test_subunit(self): |
123 | 95 | """Passing --subunit results in subunit output.""" | ||
124 | 96 | self.requireFeature(SubUnitFeature) | 96 | self.requireFeature(SubUnitFeature) |
134 | 97 | from subunit import ProtocolTestCase | 97 | params = self.get_params_passed_to_core('selftest --subunit') |
135 | 98 | stdout = self.run_bzr( | 98 | self.assertEqual(tests.SubUnitBzrRunner, params[1]['runner_class']) |
127 | 99 | 'selftest --subunit --no-plugins ' | ||
128 | 100 | 'tests.test_selftest.SelftestTests.test_import_tests')[0] | ||
129 | 101 | stream = StringIO(str(stdout)) | ||
130 | 102 | test = ProtocolTestCase(stream) | ||
131 | 103 | result = unittest.TestResult() | ||
132 | 104 | test.run(result) | ||
133 | 105 | self.assertEqual(1, result.testsRun) | ||
136 | 106 | 99 | ||
137 | 107 | 100 | ||
138 | 108 | class TestRunBzr(ExternalBase): | 101 | class TestRunBzr(ExternalBase): |
139 | @@ -512,59 +505,29 @@ | |||
140 | 512 | return (header,body,footer) | 505 | return (header,body,footer) |
141 | 513 | 506 | ||
142 | 514 | def test_list_only(self): | 507 | def test_list_only(self): |
196 | 515 | # check that bzr selftest --list-only works correctly | 508 | # check that bzr selftest --list-only outputs no ui noise |
197 | 516 | out,err = self.run_bzr('selftest selftest --list-only') | 509 | def selftest(*args, **kwargs): |
198 | 517 | (header,body,footer) = self._parse_test_list(out.splitlines()) | 510 | """Capture the arguments selftest was run with.""" |
199 | 518 | num_tests = len(body) | 511 | return True |
200 | 519 | self.assertLength(0, header) | 512 | def outputs_nothing(cmdline): |
201 | 520 | self.assertLength(0, footer) | 513 | out,err = self.run_bzr(cmdline) |
202 | 521 | self.assertEqual('', err) | 514 | (header,body,footer) = self._parse_test_list(out.splitlines()) |
203 | 522 | 515 | num_tests = len(body) | |
204 | 523 | def test_list_only_filtered(self): | 516 | self.assertLength(0, header) |
205 | 524 | # check that a filtered --list-only works, both include and exclude | 517 | self.assertLength(0, footer) |
206 | 525 | out_all,err_all = self.run_bzr('selftest --list-only') | 518 | self.assertEqual('', err) |
207 | 526 | tests_all = self._parse_test_list(out_all.splitlines())[1] | 519 | # Yes this prevents using threads to run the test suite in parallel, |
208 | 527 | out_incl,err_incl = self.run_bzr('selftest --list-only selftest') | 520 | # however we don't have a clean dependency injector for commands, |
209 | 528 | tests_incl = self._parse_test_list(out_incl.splitlines())[1] | 521 | # and even if we did - we'd still be testing that the glue is wired |
210 | 529 | self.assertSubset(tests_incl, tests_all) | 522 | # up correctly. XXX: TODO: Solve this testing problem. |
211 | 530 | out_excl,err_excl = self.run_bzr(['selftest', '--list-only', | 523 | original_selftest = tests.selftest |
212 | 531 | '--exclude', 'selftest']) | 524 | tests.selftest = selftest |
213 | 532 | tests_excl = self._parse_test_list(out_excl.splitlines())[1] | 525 | try: |
214 | 533 | self.assertSubset(tests_excl, tests_all) | 526 | outputs_nothing('selftest --list-only') |
215 | 534 | set_incl = set(tests_incl) | 527 | outputs_nothing('selftest --list-only selftest') |
216 | 535 | set_excl = set(tests_excl) | 528 | outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest']) |
217 | 536 | intersection = set_incl.intersection(set_excl) | 529 | finally: |
218 | 537 | self.assertEquals(0, len(intersection)) | 530 | tests.selftest = original_selftest |
166 | 538 | self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl)) | ||
167 | 539 | |||
168 | 540 | def test_list_only_random(self): | ||
169 | 541 | # check that --randomize works correctly | ||
170 | 542 | out_all,err_all = self.run_bzr('selftest --list-only selftest') | ||
171 | 543 | tests_all = self._parse_test_list(out_all.splitlines())[1] | ||
172 | 544 | # XXX: It looks like there are some orders for generating tests that | ||
173 | 545 | # fail as of 20070504 - maybe because of import order dependencies. | ||
174 | 546 | # So unfortunately this will rarely intermittently fail at the moment. | ||
175 | 547 | # -- mbp 20070504 | ||
176 | 548 | out_rand,err_rand = self.run_bzr(['selftest', '--list-only', | ||
177 | 549 | 'selftest', '--randomize', 'now']) | ||
178 | 550 | (header_rand,tests_rand,dummy) = self._parse_test_list( | ||
179 | 551 | out_rand.splitlines(), 1) | ||
180 | 552 | # XXX: The following line asserts that the randomized order is not the | ||
181 | 553 | # same as the default order. It is just possible that they'll get | ||
182 | 554 | # randomized into the same order and this will falsely fail, but | ||
183 | 555 | # that's very unlikely in practice because there are thousands of | ||
184 | 556 | # tests. | ||
185 | 557 | self.assertNotEqual(tests_all, tests_rand) | ||
186 | 558 | self.assertEqual(sorted(tests_all), sorted(tests_rand)) | ||
187 | 559 | # Check that the seed can be reused to get the exact same order | ||
188 | 560 | seed_re = re.compile('Randomizing test order using seed (\w+)') | ||
189 | 561 | match_obj = seed_re.search(header_rand[-1]) | ||
190 | 562 | seed = match_obj.group(1) | ||
191 | 563 | out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only', | ||
192 | 564 | 'selftest', '--randomize', seed]) | ||
193 | 565 | (header_rand2,tests_rand2,dummy) = self._parse_test_list( | ||
194 | 566 | out_rand2.splitlines(), 1) | ||
195 | 567 | self.assertEqual(tests_rand, tests_rand2) | ||
219 | 568 | 531 | ||
220 | 569 | 532 | ||
221 | 570 | class TestSelftestWithIdList(TestCaseInTempDir): | 533 | class TestSelftestWithIdList(TestCaseInTempDir): |
222 | 571 | 534 | ||
223 | === modified file 'bzrlib/tests/test_selftest.py' | |||
224 | --- bzrlib/tests/test_selftest.py 2009-08-17 03:47:03 +0000 | |||
225 | +++ bzrlib/tests/test_selftest.py 2009-08-24 05:35:11 +0000 | |||
226 | @@ -50,6 +50,7 @@ | |||
227 | 50 | deprecated_method, | 50 | deprecated_method, |
228 | 51 | ) | 51 | ) |
229 | 52 | from bzrlib.tests import ( | 52 | from bzrlib.tests import ( |
230 | 53 | SubUnitFeature, | ||
231 | 53 | test_lsprof, | 54 | test_lsprof, |
232 | 54 | test_sftp_transport, | 55 | test_sftp_transport, |
233 | 55 | TestUtil, | 56 | TestUtil, |
234 | @@ -1770,6 +1771,99 @@ | |||
235 | 1770 | test_suite_factory=factory) | 1771 | test_suite_factory=factory) |
236 | 1771 | self.assertEqual([True], factory_called) | 1772 | self.assertEqual([True], factory_called) |
237 | 1772 | 1773 | ||
238 | 1774 | def factory(self): | ||
239 | 1775 | """A test suite factory.""" | ||
240 | 1776 | class Test(tests.TestCase): | ||
241 | 1777 | def a(self): | ||
242 | 1778 | pass | ||
243 | 1779 | def b(self): | ||
244 | 1780 | pass | ||
245 | 1781 | def c(self): | ||
246 | 1782 | pass | ||
247 | 1783 | return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")]) | ||
248 | 1784 | |||
249 | 1785 | def run_selftest(self, **kwargs): | ||
250 | 1786 | """Run selftest returning its output.""" | ||
251 | 1787 | output = StringIO() | ||
252 | 1788 | old_transport = bzrlib.tests.default_transport | ||
253 | 1789 | old_root = tests.TestCaseWithMemoryTransport.TEST_ROOT | ||
254 | 1790 | tests.TestCaseWithMemoryTransport.TEST_ROOT = None | ||
255 | 1791 | try: | ||
256 | 1792 | self.assertEqual(True, tests.selftest(stream=output, **kwargs)) | ||
257 | 1793 | finally: | ||
258 | 1794 | bzrlib.tests.default_transport = old_transport | ||
259 | 1795 | tests.TestCaseWithMemoryTransport.TEST_ROOT = old_root | ||
260 | 1796 | output.seek(0) | ||
261 | 1797 | return output | ||
262 | 1798 | |||
263 | 1799 | def test_list_only(self): | ||
264 | 1800 | output = self.run_selftest(test_suite_factory=self.factory, | ||
265 | 1801 | list_only=True) | ||
266 | 1802 | self.assertEqual(3, len(output.readlines())) | ||
267 | 1803 | |||
268 | 1804 | def test_list_only_filtered(self): | ||
269 | 1805 | output = self.run_selftest(test_suite_factory=self.factory, | ||
270 | 1806 | list_only=True, pattern="Test.b") | ||
271 | 1807 | self.assertEndsWith(output.getvalue(), "Test.b\n") | ||
272 | 1808 | self.assertLength(1, output.readlines()) | ||
273 | 1809 | |||
274 | 1810 | def test_list_only_excludes(self): | ||
275 | 1811 | output = self.run_selftest(test_suite_factory=self.factory, | ||
276 | 1812 | list_only=True, exclude_pattern="Test.b") | ||
277 | 1813 | self.assertNotContainsRe("Test.b", output.getvalue()) | ||
278 | 1814 | self.assertLength(2, output.readlines()) | ||
279 | 1815 | |||
280 | 1816 | def test_random(self): | ||
281 | 1817 | # test randomising by listing a number of tests. | ||
282 | 1818 | output_123 = self.run_selftest(test_suite_factory=self.factory, | ||
283 | 1819 | list_only=True, random_seed="123") | ||
284 | 1820 | output_234 = self.run_selftest(test_suite_factory=self.factory, | ||
285 | 1821 | list_only=True, random_seed="234") | ||
286 | 1822 | self.assertNotEqual(output_123, output_234) | ||
287 | 1823 | # "Randominzing test order..\n\n | ||
288 | 1824 | self.assertLength(5, output_123.readlines()) | ||
289 | 1825 | self.assertLength(5, output_234.readlines()) | ||
290 | 1826 | |||
291 | 1827 | def test_random_reuse_is_same_order(self): | ||
292 | 1828 | # test randomising by listing a number of tests. | ||
293 | 1829 | expected = self.run_selftest(test_suite_factory=self.factory, | ||
294 | 1830 | list_only=True, random_seed="123") | ||
295 | 1831 | repeated = self.run_selftest(test_suite_factory=self.factory, | ||
296 | 1832 | list_only=True, random_seed="123") | ||
297 | 1833 | self.assertEqual(expected.getvalue(), repeated.getvalue()) | ||
298 | 1834 | |||
299 | 1835 | def test_runner_class(self): | ||
300 | 1836 | self.requireFeature(SubUnitFeature) | ||
301 | 1837 | from subunit import ProtocolTestCase | ||
302 | 1838 | stream = self.run_selftest(runner_class=tests.SubUnitBzrRunner, | ||
303 | 1839 | test_suite_factory=self.factory) | ||
304 | 1840 | test = ProtocolTestCase(stream) | ||
305 | 1841 | result = unittest.TestResult() | ||
306 | 1842 | test.run(result) | ||
307 | 1843 | self.assertEqual(3, result.testsRun) | ||
308 | 1844 | |||
309 | 1845 | def check_transport_set(self, transport_server): | ||
310 | 1846 | captured_transport = [] | ||
311 | 1847 | def seen_transport(a_transport): | ||
312 | 1848 | captured_transport.append(a_transport) | ||
313 | 1849 | class Capture(tests.TestCase): | ||
314 | 1850 | def a(self): | ||
315 | 1851 | seen_transport(bzrlib.tests.default_transport) | ||
316 | 1852 | def factory(): | ||
317 | 1853 | return TestUtil.TestSuite([Capture("a")]) | ||
318 | 1854 | self.run_selftest(transport=transport_server, test_suite_factory=factory) | ||
319 | 1855 | self.assertEqual(transport_server, captured_transport[0]) | ||
320 | 1856 | |||
321 | 1857 | def test_transport_sftp(self): | ||
322 | 1858 | try: | ||
323 | 1859 | import bzrlib.transport.sftp | ||
324 | 1860 | except ParamikoNotPresent: | ||
325 | 1861 | raise TestSkipped("Paramiko not present") | ||
326 | 1862 | self.check_transport_set(bzrlib.transport.sftp.SFTPAbsoluteServer) | ||
327 | 1863 | |||
328 | 1864 | def test_transport_memory(self): | ||
329 | 1865 | self.check_transport_set(bzrlib.transport.memory.MemoryServer) | ||
330 | 1866 | |||
331 | 1773 | 1867 | ||
332 | 1774 | class TestKnownFailure(tests.TestCase): | 1868 | class TestKnownFailure(tests.TestCase): |
333 | 1775 | 1869 |
This turns two 13 second tests into a few millisecond-scale tests
testing more precise layers.
-Rob
--