From 1fd7bc24386dbba3a9454bb49c702a642f00e34c Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Thu, 4 Feb 2021 14:39:38 -0800 Subject: sync: superproject performance changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After updating all project’s revsionIds with the SHAs from superproject, write the updated manifest into superproject_override.xml file. Reload that file for future Reloads. This file is created in exp-superproject directory. Moved most of the code that is superproject specific into git_superproject.py and wrote test code. If git pull fails, did a git clone of the superproject. We saw performance gains for consecutive repo sync's. The time to sync went down from around 120 secs to 40 secs when repo sync is executed consecutively. Tested the code with the following commands. $ ./run_tests -v tests/test_git_superproject.py $ ./run_tests -v Tested the sync code by copying all the repo changes into my Android AOSP checkout and doing a repo sync --use-superproject twice. First run $ time repo sync --use-superproject ... real 21m3.745s user 97m59.380s sys 19m11.286s After two consecutive sync runs $ time repo sync -c -j8 --use-superproject real 0m39.626s user 0m29.937s sys 0m38.155s Bug: https://crbug.com/gerrit/13709 Bug: https://crbug.com/gerrit/13707 Tested-by: Raman Tenneti Change-Id: Id79a0d7c4d20babd65e9bd485196c6f8fbe9de5e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/296082 Reviewed-by: Ian Kasprzak Tested-by: Raman Tenneti --- tests/test_git_superproject.py | 89 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index 4012ec26..d2c2f501 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py @@ -21,6 +21,7 @@ from unittest import mock from error import GitError import git_superproject +import manifest_xml import platform_utils @@ -31,27 +32,43 @@ class SuperprojectTestCase(unittest.TestCase): """Set up superproject every time.""" self.tempdir = tempfile.mkdtemp(prefix='repo_tests') self.repodir = os.path.join(self.tempdir, '.repo') - os.mkdir(self.repodir) self._superproject = git_superproject.Superproject(self.repodir) + self.manifest_file = os.path.join( + self.repodir, manifest_xml.MANIFEST_FILE_NAME) + os.mkdir(self.repodir) + + # The manifest parsing really wants a git repo currently. + gitdir = os.path.join(self.repodir, 'manifests.git') + os.mkdir(gitdir) + with open(os.path.join(gitdir, 'config'), 'w') as fp: + fp.write("""[remote "origin"] + url = https://localhost:0/manifest +""") def tearDown(self): """Tear down superproject every time.""" platform_utils.rmtree(self.tempdir) + def getXmlManifest(self, data): + """Helper to initialize a manifest for testing.""" + with open(self.manifest_file, 'w') as fp: + fp.write(data) + return manifest_xml.XmlManifest(self.repodir, self.manifest_file) + def test_superproject_get_project_shas_no_url(self): """Test with no url.""" with self.assertRaises(ValueError): - self._superproject.GetAllProjectsSHAs(url=None) + self._superproject._GetAllProjectsSHAs(url=None) def test_superproject_get_project_shas_invalid_url(self): """Test with an invalid url.""" with self.assertRaises(GitError): - self._superproject.GetAllProjectsSHAs(url='localhost') + self._superproject._GetAllProjectsSHAs(url='localhost') def test_superproject_get_project_shas_invalid_branch(self): """Test with an invalid branch.""" with self.assertRaises(GitError): - self._superproject.GetAllProjectsSHAs( + self._superproject._GetAllProjectsSHAs( url='sso://android/platform/superproject', branch='junk') @@ -59,14 +76,14 @@ class SuperprojectTestCase(unittest.TestCase): """Test with _Clone failing.""" with self.assertRaises(GitError): with mock.patch.object(self._superproject, '_Clone', return_value=False): - self._superproject.GetAllProjectsSHAs(url='localhost') + self._superproject._GetAllProjectsSHAs(url='localhost') def test_superproject_get_project_shas_mock_pull(self): """Test with _Pull failing.""" with self.assertRaises(GitError): with mock.patch.object(self._superproject, '_Clone', return_value=True): with mock.patch.object(self._superproject, '_Pull', return_value=False): - self._superproject.GetAllProjectsSHAs(url='localhost') + self._superproject._GetAllProjectsSHAs(url='localhost') def test_superproject_get_project_shas_mock_ls_tree(self): """Test with LsTree being a mock.""" @@ -77,13 +94,71 @@ class SuperprojectTestCase(unittest.TestCase): '160000 commit ade9b7a0d874e25fff4bf2552488825c6f111928\tbuild/bazel\x00') with mock.patch.object(self._superproject, '_Clone', return_value=True): with mock.patch.object(self._superproject, '_LsTree', return_value=data): - shas = self._superproject.GetAllProjectsSHAs(url='localhost', branch='junk') + shas = self._superproject._GetAllProjectsSHAs(url='localhost', branch='junk') self.assertEqual(shas, { 'art': '2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea', 'bootable/recovery': 'e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06', 'build/bazel': 'ade9b7a0d874e25fff4bf2552488825c6f111928' }) + def test_superproject_write_manifest_file(self): + """Test with writing manifest to a file after setting revisionId.""" + manifest = self.getXmlManifest(""" + + + + + +""") + self.assertEqual(len(manifest.projects), 1) + project = manifest.projects[0] + project.SetRevisionId('ABCDEF') + # Create temporary directory so that it can write the file. + os.mkdir(self._superproject._superproject_path) + manifest_path = self._superproject._WriteManfiestFile(manifest) + self.assertIsNotNone(manifest_path) + with open(manifest_path, 'r') as fp: + manifest_xml = fp.read() + self.assertEqual( + manifest_xml, + '' + + '' + + '' + + '' + + '') + + def test_superproject_update_project_revision_id(self): + """Test with LsTree being a mock.""" + manifest = self.getXmlManifest(""" + + + + + +""") + self.assertEqual(len(manifest.projects), 1) + projects = manifest.projects + data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' + '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00') + with mock.patch.object(self._superproject, '_Clone', return_value=True): + with mock.patch.object(self._superproject, '_Pull', return_value=True): + with mock.patch.object(self._superproject, '_LsTree', return_value=data): + # Create temporary directory so that it can write the file. + os.mkdir(self._superproject._superproject_path) + manifest_path = self._superproject.UpdateProjectsRevisionId( + manifest, projects, url='localhost') + self.assertIsNotNone(manifest_path) + with open(manifest_path, 'r') as fp: + manifest_xml = fp.read() + self.assertEqual( + manifest_xml, + '' + + '' + + '' + + '' + + '') + if __name__ == '__main__': unittest.main() -- cgit v1.2.3-54-g00ecf