summaryrefslogtreecommitdiffstats
path: root/tests/test_subcmds_sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_subcmds_sync.py')
-rw-r--r--tests/test_subcmds_sync.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py
index 13f3f873..236d54e5 100644
--- a/tests/test_subcmds_sync.py
+++ b/tests/test_subcmds_sync.py
@@ -13,11 +13,13 @@
13# limitations under the License. 13# limitations under the License.
14"""Unittests for the subcmds/sync.py module.""" 14"""Unittests for the subcmds/sync.py module."""
15 15
16import os
16import unittest 17import unittest
17from unittest import mock 18from unittest import mock
18 19
19import pytest 20import pytest
20 21
22import command
21from subcmds import sync 23from subcmds import sync
22 24
23 25
@@ -43,6 +45,51 @@ def test_get_current_branch_only(use_superproject, cli_args, result):
43 assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result 45 assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result
44 46
45 47
48# Used to patch os.cpu_count() for reliable results.
49OS_CPU_COUNT = 24
50
51@pytest.mark.parametrize('argv, jobs_manifest, jobs, jobs_net, jobs_check', [
52 # No user or manifest settings.
53 ([], None, OS_CPU_COUNT, 1, command.DEFAULT_LOCAL_JOBS),
54 # No user settings, so manifest settings control.
55 ([], 3, 3, 3, 3),
56 # User settings, but no manifest.
57 (['--jobs=4'], None, 4, 4, 4),
58 (['--jobs=4', '--jobs-network=5'], None, 4, 5, 4),
59 (['--jobs=4', '--jobs-checkout=6'], None, 4, 4, 6),
60 (['--jobs=4', '--jobs-network=5', '--jobs-checkout=6'], None, 4, 5, 6),
61 (['--jobs-network=5'], None, OS_CPU_COUNT, 5, command.DEFAULT_LOCAL_JOBS),
62 (['--jobs-checkout=6'], None, OS_CPU_COUNT, 1, 6),
63 (['--jobs-network=5', '--jobs-checkout=6'], None, OS_CPU_COUNT, 5, 6),
64 # User settings with manifest settings.
65 (['--jobs=4'], 3, 4, 4, 4),
66 (['--jobs=4', '--jobs-network=5'], 3, 4, 5, 4),
67 (['--jobs=4', '--jobs-checkout=6'], 3, 4, 4, 6),
68 (['--jobs=4', '--jobs-network=5', '--jobs-checkout=6'], 3, 4, 5, 6),
69 (['--jobs-network=5'], 3, 3, 5, 3),
70 (['--jobs-checkout=6'], 3, 3, 3, 6),
71 (['--jobs-network=5', '--jobs-checkout=6'], 3, 3, 5, 6),
72 # Settings that exceed rlimits get capped.
73 (['--jobs=1000000'], None, 83, 83, 83),
74 ([], 1000000, 83, 83, 83),
75])
76def test_cli_jobs(argv, jobs_manifest, jobs, jobs_net, jobs_check):
77 """Tests --jobs option behavior."""
78 mp = mock.MagicMock()
79 mp.manifest.default.sync_j = jobs_manifest
80
81 cmd = sync.Sync()
82 opts, args = cmd.OptionParser.parse_args(argv)
83 cmd.ValidateOptions(opts, args)
84
85 with mock.patch.object(sync, '_rlimit_nofile', return_value=(256, 256)):
86 with mock.patch.object(os, 'cpu_count', return_value=OS_CPU_COUNT):
87 cmd._ValidateOptionsWithManifest(opts, mp)
88 assert opts.jobs == jobs
89 assert opts.jobs_network == jobs_net
90 assert opts.jobs_checkout == jobs_check
91
92
46class GetPreciousObjectsState(unittest.TestCase): 93class GetPreciousObjectsState(unittest.TestCase):
47 """Tests for _GetPreciousObjectsState.""" 94 """Tests for _GetPreciousObjectsState."""
48 95