Merge lp:~lifeless/bzr/test-speed into lp:~bzr/bzr/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
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+10584@code.launchpad.net

This proposal supersedes a proposal from 2009-08-23.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote : Posted in a previous version of this proposal

This turns two 13 second tests into a few millisecond-scale tests
testing more precise layers.

-Rob

--

Revision history for this message
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
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
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
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py 2009-08-20 05:05:59 +0000
+++ bzrlib/tests/__init__.py 2009-08-24 05:35:11 +0000
@@ -3207,6 +3207,7 @@
3207 starting_with=None,3207 starting_with=None,
3208 runner_class=None,3208 runner_class=None,
3209 suite_decorators=None,3209 suite_decorators=None,
3210 stream=None,
3210 ):3211 ):
3211 """Run the whole test suite under the enhanced runner"""3212 """Run the whole test suite under the enhanced runner"""
3212 # XXX: Very ugly way to do this...3213 # XXX: Very ugly way to do this...
@@ -3245,6 +3246,7 @@
3245 strict=strict,3246 strict=strict,
3246 runner_class=runner_class,3247 runner_class=runner_class,
3247 suite_decorators=suite_decorators,3248 suite_decorators=suite_decorators,
3249 stream=stream,
3248 )3250 )
3249 finally:3251 finally:
3250 default_transport = old_transport3252 default_transport = old_transport
32513253
=== modified file 'bzrlib/tests/blackbox/test_selftest.py'
--- bzrlib/tests/blackbox/test_selftest.py 2009-07-10 07:14:02 +0000
+++ bzrlib/tests/blackbox/test_selftest.py 2009-08-24 05:35:11 +0000
@@ -26,6 +26,7 @@
26import bzrlib26import bzrlib
27from bzrlib import (27from bzrlib import (
28 osutils,28 osutils,
29 tests,
29 )30 )
30from bzrlib.errors import ParamikoNotPresent31from bzrlib.errors import ParamikoNotPresent
31from bzrlib.tests import (32from bzrlib.tests import (
@@ -42,67 +43,59 @@
4243
43class TestOptions(TestCase):44class TestOptions(TestCase):
4445
45 current_test = None
46
47 def test_transport_set_to_sftp(self):46 def test_transport_set_to_sftp(self):
48 # test the --transport option has taken effect from within the47 # Test that we can pass a transport to the selftest core - sftp
49 # test_transport test48 # version.
50 try:49 try:
51 import bzrlib.transport.sftp50 import bzrlib.transport.sftp
52 except ParamikoNotPresent:51 except ParamikoNotPresent:
53 raise TestSkipped("Paramiko not present")52 raise TestSkipped("Paramiko not present")
54 if TestOptions.current_test != "test_transport_set_to_sftp":53 params = self.get_params_passed_to_core('selftest --transport=sftp')
55 return
56 self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,54 self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,
57 bzrlib.tests.default_transport)55 params[1]["transport"])
5856
59 def test_transport_set_to_memory(self):57 def test_transport_set_to_memory(self):
60 # test the --transport option has taken effect from within the58 # Test that we can pass a transport to the selftest core - memory
61 # test_transport test59 # version.
62 import bzrlib.transport.memory60 import bzrlib.transport.memory
63 if TestOptions.current_test != "test_transport_set_to_memory":61 params = self.get_params_passed_to_core('selftest --transport=memory')
64 return
65 self.assertEqual(bzrlib.transport.memory.MemoryServer,62 self.assertEqual(bzrlib.transport.memory.MemoryServer,
66 bzrlib.tests.default_transport)63 params[1]["transport"])
6764
68 def test_transport(self):65 def get_params_passed_to_core(self, cmdline):
69 # test that --transport=sftp works66 params = []
70 try:67 def selftest(*args, **kwargs):
71 import bzrlib.transport.sftp68 """Capture the arguments selftest was run with."""
72 except ParamikoNotPresent:69 params.append((args, kwargs))
73 raise TestSkipped("Paramiko not present")70 return True
74 old_transport = bzrlib.tests.default_transport71 # Yes this prevents using threads to run the test suite in parallel,
75 old_root = TestCaseWithMemoryTransport.TEST_ROOT72 # however we don't have a clean dependency injector for commands,
76 TestCaseWithMemoryTransport.TEST_ROOT = None73 # and even if we did - we'd still be testing that the glue is wired
77 try:74 # up correctly. XXX: TODO: Solve this testing problem.
78 TestOptions.current_test = "test_transport_set_to_sftp"75 original_selftest = tests.selftest
79 stdout = self.run_bzr(76 tests.selftest = selftest
80 'selftest --transport=sftp test_transport_set_to_sftp')[0]77 try:
81 self.assertContainsRe(stdout, 'Ran 1 test')78 self.run_bzr(cmdline)
82 self.assertEqual(old_transport, bzrlib.tests.default_transport)79 return params[0]
83
84 TestOptions.current_test = "test_transport_set_to_memory"
85 stdout = self.run_bzr(
86 'selftest --transport=memory test_transport_set_to_memory')[0]
87 self.assertContainsRe(stdout, 'Ran 1 test')
88 self.assertEqual(old_transport, bzrlib.tests.default_transport)
89 finally:80 finally:
90 bzrlib.tests.default_transport = old_transport81 tests.selftest = original_selftest
91 TestOptions.current_test = None82
92 TestCaseWithMemoryTransport.TEST_ROOT = old_root83 def test_parameters_passed_to_core(self):
84 params = self.get_params_passed_to_core('selftest --list-only')
85 self.assertTrue("list_only" in params[1])
86 params = self.get_params_passed_to_core('selftest --list-only selftest')
87 self.assertTrue("list_only" in params[1])
88 params = self.get_params_passed_to_core(['selftest', '--list-only',
89 '--exclude', 'selftest'])
90 self.assertTrue("list_only" in params[1])
91 params = self.get_params_passed_to_core(['selftest', '--list-only',
92 'selftest', '--randomize', 'now'])
93 self.assertSubset(["list_only", "random_seed"], params[1])
9394
94 def test_subunit(self):95 def test_subunit(self):
95 """Passing --subunit results in subunit output."""
96 self.requireFeature(SubUnitFeature)96 self.requireFeature(SubUnitFeature)
97 from subunit import ProtocolTestCase97 params = self.get_params_passed_to_core('selftest --subunit')
98 stdout = self.run_bzr(98 self.assertEqual(tests.SubUnitBzrRunner, params[1]['runner_class'])
99 'selftest --subunit --no-plugins '
100 'tests.test_selftest.SelftestTests.test_import_tests')[0]
101 stream = StringIO(str(stdout))
102 test = ProtocolTestCase(stream)
103 result = unittest.TestResult()
104 test.run(result)
105 self.assertEqual(1, result.testsRun)
10699
107100
108class TestRunBzr(ExternalBase):101class TestRunBzr(ExternalBase):
@@ -512,59 +505,29 @@
512 return (header,body,footer)505 return (header,body,footer)
513506
514 def test_list_only(self):507 def test_list_only(self):
515 # check that bzr selftest --list-only works correctly508 # check that bzr selftest --list-only outputs no ui noise
516 out,err = self.run_bzr('selftest selftest --list-only')509 def selftest(*args, **kwargs):
517 (header,body,footer) = self._parse_test_list(out.splitlines())510 """Capture the arguments selftest was run with."""
518 num_tests = len(body)511 return True
519 self.assertLength(0, header)512 def outputs_nothing(cmdline):
520 self.assertLength(0, footer)513 out,err = self.run_bzr(cmdline)
521 self.assertEqual('', err)514 (header,body,footer) = self._parse_test_list(out.splitlines())
522515 num_tests = len(body)
523 def test_list_only_filtered(self):516 self.assertLength(0, header)
524 # check that a filtered --list-only works, both include and exclude517 self.assertLength(0, footer)
525 out_all,err_all = self.run_bzr('selftest --list-only')518 self.assertEqual('', err)
526 tests_all = self._parse_test_list(out_all.splitlines())[1]519 # Yes this prevents using threads to run the test suite in parallel,
527 out_incl,err_incl = self.run_bzr('selftest --list-only selftest')520 # however we don't have a clean dependency injector for commands,
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
529 self.assertSubset(tests_incl, tests_all)522 # up correctly. XXX: TODO: Solve this testing problem.
530 out_excl,err_excl = self.run_bzr(['selftest', '--list-only',523 original_selftest = tests.selftest
531 '--exclude', 'selftest'])524 tests.selftest = selftest
532 tests_excl = self._parse_test_list(out_excl.splitlines())[1]525 try:
533 self.assertSubset(tests_excl, tests_all)526 outputs_nothing('selftest --list-only')
534 set_incl = set(tests_incl)527 outputs_nothing('selftest --list-only selftest')
535 set_excl = set(tests_excl)528 outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest'])
536 intersection = set_incl.intersection(set_excl)529 finally:
537 self.assertEquals(0, len(intersection))530 tests.selftest = original_selftest
538 self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl))
539
540 def test_list_only_random(self):
541 # check that --randomize works correctly
542 out_all,err_all = self.run_bzr('selftest --list-only selftest')
543 tests_all = self._parse_test_list(out_all.splitlines())[1]
544 # XXX: It looks like there are some orders for generating tests that
545 # fail as of 20070504 - maybe because of import order dependencies.
546 # So unfortunately this will rarely intermittently fail at the moment.
547 # -- mbp 20070504
548 out_rand,err_rand = self.run_bzr(['selftest', '--list-only',
549 'selftest', '--randomize', 'now'])
550 (header_rand,tests_rand,dummy) = self._parse_test_list(
551 out_rand.splitlines(), 1)
552 # XXX: The following line asserts that the randomized order is not the
553 # same as the default order. It is just possible that they'll get
554 # randomized into the same order and this will falsely fail, but
555 # that's very unlikely in practice because there are thousands of
556 # tests.
557 self.assertNotEqual(tests_all, tests_rand)
558 self.assertEqual(sorted(tests_all), sorted(tests_rand))
559 # Check that the seed can be reused to get the exact same order
560 seed_re = re.compile('Randomizing test order using seed (\w+)')
561 match_obj = seed_re.search(header_rand[-1])
562 seed = match_obj.group(1)
563 out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',
564 'selftest', '--randomize', seed])
565 (header_rand2,tests_rand2,dummy) = self._parse_test_list(
566 out_rand2.splitlines(), 1)
567 self.assertEqual(tests_rand, tests_rand2)
568531
569532
570class TestSelftestWithIdList(TestCaseInTempDir):533class TestSelftestWithIdList(TestCaseInTempDir):
571534
=== modified file 'bzrlib/tests/test_selftest.py'
--- bzrlib/tests/test_selftest.py 2009-08-17 03:47:03 +0000
+++ bzrlib/tests/test_selftest.py 2009-08-24 05:35:11 +0000
@@ -50,6 +50,7 @@
50 deprecated_method,50 deprecated_method,
51 )51 )
52from bzrlib.tests import (52from bzrlib.tests import (
53 SubUnitFeature,
53 test_lsprof,54 test_lsprof,
54 test_sftp_transport,55 test_sftp_transport,
55 TestUtil,56 TestUtil,
@@ -1770,6 +1771,99 @@
1770 test_suite_factory=factory)1771 test_suite_factory=factory)
1771 self.assertEqual([True], factory_called)1772 self.assertEqual([True], factory_called)
17721773
1774 def factory(self):
1775 """A test suite factory."""
1776 class Test(tests.TestCase):
1777 def a(self):
1778 pass
1779 def b(self):
1780 pass
1781 def c(self):
1782 pass
1783 return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
1784
1785 def run_selftest(self, **kwargs):
1786 """Run selftest returning its output."""
1787 output = StringIO()
1788 old_transport = bzrlib.tests.default_transport
1789 old_root = tests.TestCaseWithMemoryTransport.TEST_ROOT
1790 tests.TestCaseWithMemoryTransport.TEST_ROOT = None
1791 try:
1792 self.assertEqual(True, tests.selftest(stream=output, **kwargs))
1793 finally:
1794 bzrlib.tests.default_transport = old_transport
1795 tests.TestCaseWithMemoryTransport.TEST_ROOT = old_root
1796 output.seek(0)
1797 return output
1798
1799 def test_list_only(self):
1800 output = self.run_selftest(test_suite_factory=self.factory,
1801 list_only=True)
1802 self.assertEqual(3, len(output.readlines()))
1803
1804 def test_list_only_filtered(self):
1805 output = self.run_selftest(test_suite_factory=self.factory,
1806 list_only=True, pattern="Test.b")
1807 self.assertEndsWith(output.getvalue(), "Test.b\n")
1808 self.assertLength(1, output.readlines())
1809
1810 def test_list_only_excludes(self):
1811 output = self.run_selftest(test_suite_factory=self.factory,
1812 list_only=True, exclude_pattern="Test.b")
1813 self.assertNotContainsRe("Test.b", output.getvalue())
1814 self.assertLength(2, output.readlines())
1815
1816 def test_random(self):
1817 # test randomising by listing a number of tests.
1818 output_123 = self.run_selftest(test_suite_factory=self.factory,
1819 list_only=True, random_seed="123")
1820 output_234 = self.run_selftest(test_suite_factory=self.factory,
1821 list_only=True, random_seed="234")
1822 self.assertNotEqual(output_123, output_234)
1823 # "Randominzing test order..\n\n
1824 self.assertLength(5, output_123.readlines())
1825 self.assertLength(5, output_234.readlines())
1826
1827 def test_random_reuse_is_same_order(self):
1828 # test randomising by listing a number of tests.
1829 expected = self.run_selftest(test_suite_factory=self.factory,
1830 list_only=True, random_seed="123")
1831 repeated = self.run_selftest(test_suite_factory=self.factory,
1832 list_only=True, random_seed="123")
1833 self.assertEqual(expected.getvalue(), repeated.getvalue())
1834
1835 def test_runner_class(self):
1836 self.requireFeature(SubUnitFeature)
1837 from subunit import ProtocolTestCase
1838 stream = self.run_selftest(runner_class=tests.SubUnitBzrRunner,
1839 test_suite_factory=self.factory)
1840 test = ProtocolTestCase(stream)
1841 result = unittest.TestResult()
1842 test.run(result)
1843 self.assertEqual(3, result.testsRun)
1844
1845 def check_transport_set(self, transport_server):
1846 captured_transport = []
1847 def seen_transport(a_transport):
1848 captured_transport.append(a_transport)
1849 class Capture(tests.TestCase):
1850 def a(self):
1851 seen_transport(bzrlib.tests.default_transport)
1852 def factory():
1853 return TestUtil.TestSuite([Capture("a")])
1854 self.run_selftest(transport=transport_server, test_suite_factory=factory)
1855 self.assertEqual(transport_server, captured_transport[0])
1856
1857 def test_transport_sftp(self):
1858 try:
1859 import bzrlib.transport.sftp
1860 except ParamikoNotPresent:
1861 raise TestSkipped("Paramiko not present")
1862 self.check_transport_set(bzrlib.transport.sftp.SFTPAbsoluteServer)
1863
1864 def test_transport_memory(self):
1865 self.check_transport_set(bzrlib.transport.memory.MemoryServer)
1866
17731867
1774class TestKnownFailure(tests.TestCase):1868class TestKnownFailure(tests.TestCase):
17751869