mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-05-07 19:39:18 +00:00
manifest: Introduce sync-j-max attribute to cap sync jobs
Add a way for manifest owners to limit how many sync jobs run in parallel. Bug: 481100878 Change-Id: Ia6cbe02cbc83c9e414b53b8d14fe5e7e1b802505 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/548963 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -401,6 +401,32 @@ class XmlManifestTests(ManifestParseTestCase):
|
||||
self.assertEqual(len(manifest.projects), 1)
|
||||
self.assertEqual(manifest.projects[0].name, "test-project")
|
||||
|
||||
def test_sync_j_max(self):
|
||||
"""Check sync-j-max handling."""
|
||||
# Check valid value.
|
||||
manifest = self.getXmlManifest(
|
||||
'<manifest><default sync-j-max="5" /></manifest>'
|
||||
)
|
||||
self.assertEqual(manifest.default.sync_j_max, 5)
|
||||
self.assertEqual(
|
||||
manifest.ToXml().toxml(),
|
||||
'<?xml version="1.0" ?>'
|
||||
'<manifest><default sync-j-max="5"/></manifest>',
|
||||
)
|
||||
|
||||
# Check invalid values.
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest = self.getXmlManifest(
|
||||
'<manifest><default sync-j-max="0" /></manifest>'
|
||||
)
|
||||
manifest.ToXml()
|
||||
|
||||
with self.assertRaises(error.ManifestParseError):
|
||||
manifest = self.getXmlManifest(
|
||||
'<manifest><default sync-j-max="-1" /></manifest>'
|
||||
)
|
||||
manifest.ToXml()
|
||||
|
||||
|
||||
class IncludeElementTests(ManifestParseTestCase):
|
||||
"""Tests for <include>."""
|
||||
|
||||
@@ -97,6 +97,35 @@ def test_cli_jobs(argv, jobs_manifest, jobs, jobs_net, jobs_check):
|
||||
"""Tests --jobs option behavior."""
|
||||
mp = mock.MagicMock()
|
||||
mp.manifest.default.sync_j = jobs_manifest
|
||||
mp.manifest.default.sync_j_max = None
|
||||
|
||||
cmd = sync.Sync()
|
||||
opts, args = cmd.OptionParser.parse_args(argv)
|
||||
cmd.ValidateOptions(opts, args)
|
||||
|
||||
with mock.patch.object(sync, "_rlimit_nofile", return_value=(256, 256)):
|
||||
with mock.patch.object(os, "cpu_count", return_value=OS_CPU_COUNT):
|
||||
cmd._ValidateOptionsWithManifest(opts, mp)
|
||||
assert opts.jobs == jobs
|
||||
assert opts.jobs_network == jobs_net
|
||||
assert opts.jobs_checkout == jobs_check
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"argv, jobs_manifest, jobs_manifest_max, jobs, jobs_net, jobs_check",
|
||||
[
|
||||
(["--jobs=10"], None, 5, 5, 5, 5),
|
||||
(["--jobs=10", "--jobs-network=10"], None, 5, 5, 5, 5),
|
||||
(["--jobs=10", "--jobs-checkout=10"], None, 5, 5, 5, 5),
|
||||
],
|
||||
)
|
||||
def test_cli_jobs_sync_j_max(
|
||||
argv, jobs_manifest, jobs_manifest_max, jobs, jobs_net, jobs_check
|
||||
):
|
||||
"""Tests --jobs option behavior with sync-j-max."""
|
||||
mp = mock.MagicMock()
|
||||
mp.manifest.default.sync_j = jobs_manifest
|
||||
mp.manifest.default.sync_j_max = jobs_manifest_max
|
||||
|
||||
cmd = sync.Sync()
|
||||
opts, args = cmd.OptionParser.parse_args(argv)
|
||||
|
||||
Reference in New Issue
Block a user