Merge lp:~lifeless/bzr/test-speed into lp:~bzr/bzr/trunk-old

Proposed by Robert Collins
Status: Superseded
Proposed branch: lp:~lifeless/bzr/test-speed
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 204 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+10582@code.launchpad.net

This proposal has been superseded by a proposal from 2009-08-23.

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

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 :

I think those upper-layer tests are almost pointless, but fixing the lower layers to work on smaller data is certainly welcome.

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-23 22:35:09 +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-23 22:35:09 +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 (
@@ -512,59 +513,55 @@
512 return (header,body,footer)513 return (header,body,footer)
513514
514 def test_list_only(self):515 def test_list_only(self):
515 # check that bzr selftest --list-only works correctly516 # check that bzr selftest --list-only outputs no ui noise
516 out,err = self.run_bzr('selftest selftest --list-only')517 def selftest(*args, **kwargs):
517 (header,body,footer) = self._parse_test_list(out.splitlines())518 """Capture the arguments selftest was run with."""
518 num_tests = len(body)519 return True
519 self.assertLength(0, header)520 def outputs_nothing(cmdline):
520 self.assertLength(0, footer)521 out,err = self.run_bzr(cmdline)
521 self.assertEqual('', err)522 (header,body,footer) = self._parse_test_list(out.splitlines())
522523 num_tests = len(body)
523 def test_list_only_filtered(self):524 self.assertLength(0, header)
524 # check that a filtered --list-only works, both include and exclude525 self.assertLength(0, footer)
525 out_all,err_all = self.run_bzr('selftest --list-only')526 self.assertEqual('', err)
526 tests_all = self._parse_test_list(out_all.splitlines())[1]527 # Yes this prevents using threads to run the test suite in parallel,
527 out_incl,err_incl = self.run_bzr('selftest --list-only selftest')528 # however we don't have a clean dependency injector for commands,
528 tests_incl = self._parse_test_list(out_incl.splitlines())[1]529 # and even if we did - we'd still be testing that the glue is wired
529 self.assertSubset(tests_incl, tests_all)530 # up correctly. XXX: TODO: Solve this testing problem.
530 out_excl,err_excl = self.run_bzr(['selftest', '--list-only',531 original_selftest = tests.selftest
531 '--exclude', 'selftest'])532 tests.selftest = selftest
532 tests_excl = self._parse_test_list(out_excl.splitlines())[1]533 try:
533 self.assertSubset(tests_excl, tests_all)534 outputs_nothing('selftest --list-only')
534 set_incl = set(tests_incl)535 outputs_nothing('selftest --list-only selftest')
535 set_excl = set(tests_excl)536 outputs_nothing(['selftest', '--list-only', '--exclude', 'selftest'])
536 intersection = set_incl.intersection(set_excl)537 finally:
537 self.assertEquals(0, len(intersection))538 tests.selftest = original_selftest
538 self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl))539
539540 def test_parameters_passed_to_core(self):
540 def test_list_only_random(self):541 params = []
541 # check that --randomize works correctly542 def selftest(*args, **kwargs):
542 out_all,err_all = self.run_bzr('selftest --list-only selftest')543 """Capture the arguments selftest was run with."""
543 tests_all = self._parse_test_list(out_all.splitlines())[1]544 params.append((args, kwargs))
544 # XXX: It looks like there are some orders for generating tests that545 return True
545 # fail as of 20070504 - maybe because of import order dependencies.546 # Yes this prevents using threads to run the test suite in parallel,
546 # So unfortunately this will rarely intermittently fail at the moment.547 # however we don't have a clean dependency injector for commands,
547 # -- mbp 20070504548 # and even if we did - we'd still be testing that the glue is wired
548 out_rand,err_rand = self.run_bzr(['selftest', '--list-only',549 # up correctly. XXX: TODO: Solve this testing problem.
549 'selftest', '--randomize', 'now'])550 original_selftest = tests.selftest
550 (header_rand,tests_rand,dummy) = self._parse_test_list(551 tests.selftest = selftest
551 out_rand.splitlines(), 1)552 try:
552 # XXX: The following line asserts that the randomized order is not the553 self.run_bzr('selftest --list-only')
553 # same as the default order. It is just possible that they'll get554 self.run_bzr('selftest --list-only selftest')
554 # randomized into the same order and this will falsely fail, but555 self.run_bzr(['selftest', '--list-only', '--exclude', 'selftest'])
555 # that's very unlikely in practice because there are thousands of556 self.run_bzr(['selftest', '--list-only', 'selftest',
556 # tests.557 '--randomize', 'now'])
557 self.assertNotEqual(tests_all, tests_rand)558 # list_only should have been passed in each invocation.
558 self.assertEqual(sorted(tests_all), sorted(tests_rand))559 self.assertTrue("list_only" in params[0][1])
559 # Check that the seed can be reused to get the exact same order560 self.assertTrue("list_only" in params[1][1])
560 seed_re = re.compile('Randomizing test order using seed (\w+)')561 self.assertTrue("list_only" in params[2][1])
561 match_obj = seed_re.search(header_rand[-1])562 self.assertSubset(["list_only", "random_seed"], params[2][1])
562 seed = match_obj.group(1)563 finally:
563 out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',564 tests.selftest = original_selftest
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)
568565
569566
570class TestSelftestWithIdList(TestCaseInTempDir):567class TestSelftestWithIdList(TestCaseInTempDir):
571568
=== 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-23 22:35:09 +0000
@@ -1770,6 +1770,60 @@
1770 test_suite_factory=factory)1770 test_suite_factory=factory)
1771 self.assertEqual([True], factory_called)1771 self.assertEqual([True], factory_called)
17721772
1773 def factory(self):
1774 """A test suite factory."""
1775 class Test(tests.TestCase):
1776 def a(self):
1777 pass
1778 def b(self):
1779 pass
1780 def c(self):
1781 pass
1782 return TestUtil.TestSuite([Test("a"), Test("b"), Test("c")])
1783
1784 def run_selftest(self, **kwargs):
1785 """Run selftest returning its output."""
1786 output = StringIO()
1787 self.assertEqual(True, tests.selftest(stream=output, **kwargs))
1788 output.seek(0)
1789 return output
1790
1791 def test_list_only(self):
1792 output = self.run_selftest(test_suite_factory=self.factory,
1793 list_only=True)
1794 self.assertEqual(3, len(output.readlines()))
1795
1796 def test_list_only_filtered(self):
1797 output = self.run_selftest(test_suite_factory=self.factory,
1798 list_only=True, pattern="Test.b")
1799 self.assertEndsWith(output.getvalue(), "Test.b\n")
1800 self.assertLength(1, output.readlines())
1801
1802 def test_list_only_excludes(self):
1803 output = self.run_selftest(test_suite_factory=self.factory,
1804 list_only=True, exclude_pattern="Test.b")
1805 self.assertNotContainsRe("Test.b", output.getvalue())
1806 self.assertLength(2, output.readlines())
1807
1808 def test_random(self):
1809 # test randomising by listing a number of tests.
1810 output_123 = self.run_selftest(test_suite_factory=self.factory,
1811 list_only=True, random_seed="123")
1812 output_234 = self.run_selftest(test_suite_factory=self.factory,
1813 list_only=True, random_seed="234")
1814 self.assertNotEqual(output_123, output_234)
1815 # "Randominzing test order..\n\n
1816 self.assertLength(5, output_123.readlines())
1817 self.assertLength(5, output_234.readlines())
1818
1819 def test_random_reuse_is_same_order(self):
1820 # test randomising by listing a number of tests.
1821 expected = self.run_selftest(test_suite_factory=self.factory,
1822 list_only=True, random_seed="123")
1823 repeated = self.run_selftest(test_suite_factory=self.factory,
1824 list_only=True, random_seed="123")
1825 self.assertEqual(expected.getvalue(), repeated.getvalue())
1826
17731827
1774class TestKnownFailure(tests.TestCase):1828class TestKnownFailure(tests.TestCase):
17751829