Merge lp:~thumper/launchpad/fix-TestSharingMigrationPerformance into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Merged at revision: 11363
Proposed branch: lp:~thumper/launchpad/fix-TestSharingMigrationPerformance
Merge into: lp:launchpad
Diff against target: 114 lines (+29/-61)
1 file modified
lib/lp/translations/scripts/tests/test_message_sharing_migration.py (+29/-61)
To merge this branch: bzr merge lp:~thumper/launchpad/fix-TestSharingMigrationPerformance
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+32828@code.launchpad.net

Commit message

Fix TestSharingMigrationPerformance to not call gc.get_objects().

Description of the change

Fix the lp.translations.scripts.tests.test_message_sharing_migration.TestSharingMigrationPerformance test to not use gc.get_objects() as this interacts badly with bzrlib lazy imports.

The test is also a little more explicit.

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

Its also a very expensive function to call. This is much more appropriate.

Small nit:
+from lp.testing import (
+ record_statements,
+ TestCaseWithFactory)

should be
+from lp.testing import (
+ record_statements,
+ TestCaseWithFactory,
+ )

as per the list policy in the wiki.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/scripts/tests/test_message_sharing_migration.py'
--- lib/lp/translations/scripts/tests/test_message_sharing_migration.py 2009-11-27 12:50:16 +0000
+++ lib/lp/translations/scripts/tests/test_message_sharing_migration.py 2010-08-17 02:31:46 +0000
@@ -13,7 +13,10 @@
13from zope.security.proxy import removeSecurityProxy13from zope.security.proxy import removeSecurityProxy
1414
15from lp.services.worlddata.interfaces.language import ILanguageSet15from lp.services.worlddata.interfaces.language import ILanguageSet
16from lp.testing import TestCaseWithFactory16from lp.testing import (
17 record_statements,
18 TestCaseWithFactory,
19 )
17from lp.translations.interfaces.pofiletranslator import (20from lp.translations.interfaces.pofiletranslator import (
18 IPOFileTranslatorSet)21 IPOFileTranslatorSet)
19from lp.translations.model.pomsgid import POMsgID22from lp.translations.model.pomsgid import POMsgID
@@ -742,22 +745,6 @@
742 transaction.commit()745 transaction.commit()
743 gc.collect()746 gc.collect()
744747
745 def _listLoadedObjects(self, of_class, ignore_list=None):
746 """Return the set of objects of a given type that are in memory.
747
748 :param of_class: A class to filter for.
749 :param ignore_list: A previous return value. Any POMsgIDs that
750 were already in that list are ignored here.
751 """
752 pomsgids = set([
753 whatever
754 for whatever in gc.get_objects()
755 if isinstance(whatever, of_class)
756 ])
757 if ignore_list is not None:
758 pomsgids -= ignore_list
759 return pomsgids
760
761 def _resetReferences(self):748 def _resetReferences(self):
762 """Reset translation-related references in the test object.749 """Reset translation-related references in the test object.
763750
@@ -782,50 +769,31 @@
782769
783 self.templates = [POTemplate.get(id) for id in template_ids]770 self.templates = [POTemplate.get(id) for id in template_ids]
784771
785 def test_merging_loads_no_msgids(self):772 def assertNoStatementsInvolvingTable(self, table_name, statements):
786 # Migration does not load actual msgids into memory.773 """The specified table name is not in any of the statements."""
787 self._flushDbObjects()774 table_name = table_name.upper()
788 msgids_before = self._listLoadedObjects(POMsgID)775 self.assertFalse(
789776 any([table_name in statement.upper()
790 self._makeTranslationMessages('x', 'y', trunk_diverged=True)777 for statement in statements]))
791 self._makeTranslationMessages('1', '2', stable_diverged=True)778
792779 def test_merging_loads_no_msgids_or_potranslations(self):
793 self._resetReferences()780 # Migration does not touch the POMsgID or POTranslation tables.
794 self.assertNotEqual([], self.templates)781 self._makeTranslationMessages('x', 'y', trunk_diverged=True)
795 self.assertEqual(782 self._makeTranslationMessages('1', '2', stable_diverged=True)
796 set(), self._listLoadedObjects(POMsgID, msgids_before))783 self._resetReferences()
797 784 self.assertNotEqual([], self.templates)
798 self.script._mergePOTMsgSets(self.templates)785
799 self.script._mergeTranslationMessages(self.templates)786 _ignored, statements = record_statements(
800787 self.script._mergePOTMsgSets, self.templates)
801 self.assertEqual(788 self.assertNoStatementsInvolvingTable(POMsgID._table, statements)
802 set(), self._listLoadedObjects(POMsgID, msgids_before))789 self.assertNoStatementsInvolvingTable(
803790 POTranslation._table, statements)
804 def test_merging_loads_no_potranslations(self):791
805 # Migration does not load actual POTranslations into memory.792 _ignored, statements = record_statements(
806 self._flushDbObjects()793 self.script._mergeTranslationMessages, self.templates)
807 potranslations_before = self._listLoadedObjects(POTranslation)794 self.assertNoStatementsInvolvingTable(POMsgID._table, statements)
808795 self.assertNoStatementsInvolvingTable(
809 self._makeTranslationMessages('x', 'y', trunk_diverged=True)796 POTranslation._table, statements)
810 self._makeTranslationMessages('1', '2', stable_diverged=True)
811
812 self._resetReferences()
813 self.assertNotEqual([], self.templates)
814 self.assertEqual(
815 set(),
816 self._listLoadedObjects(POTranslation, potranslations_before))
817
818 self.script._mergePOTMsgSets(self.templates)
819
820 self.assertEqual(
821 set(),
822 self._listLoadedObjects(POTranslation, potranslations_before))
823
824 self.script._mergeTranslationMessages(self.templates)
825
826 self.assertEqual(
827 set(),
828 self._listLoadedObjects(POTranslation, potranslations_before))
829797
830798
831def test_suite():799def test_suite():