Caffeinate fetches on Mac.

Since fetches involve multiple subprocess calls, any of which can be
slow, the per-subprocess caffeination strategy does not seem suitable --
the Mac might sleep as soon as the wake lock is dropped, before it
starts a new one. This instead implements a context manager to allow
caffeinating a scope.

To allow flag control, caffeinate.scope takes an argument that decides
whether or not it should actually do anything useful; it looks silly,
but the alternative is to interfere with flag parsing more or to require
users to write separate codepaths to decide whether to enter the context
manager scope or not; the "use the context manager in a mode where it
does not do anything" prevents this.

Bug: 462507017
Change-Id: Icc5bb9cadda30b5a120f112b10bf96ffd3b6550f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7183647
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Adam Norberg <norberg@google.com>
This commit is contained in:
Adam Norberg
2025-11-21 14:01:25 -08:00
committed by LUCI CQ
parent b738decbef
commit 3d401c263f
3 changed files with 47 additions and 3 deletions

View File

@@ -49,6 +49,7 @@ class TestUtilityFunctions(unittest.TestCase):
force=False,
config='foo',
protocol_override=None,
caffeinate=True,
props=[]), response)
response = fetch.handle_args([
@@ -63,11 +64,13 @@ class TestUtilityFunctions(unittest.TestCase):
force=True,
config='foo',
protocol_override='sso',
caffeinate=True,
props=['--some-param=1', '--bar=2']), response)
response = fetch.handle_args([
'filename', '-n', '--dry-run', '--no-hooks', '--nohistory',
'--force', '-p', 'sso', 'foo', '--some-param=1', '--bar=2'
'--force', '--no-caffeinate', '-p', 'sso', 'foo', '--some-param=1',
'--bar=2'
])
self.assertEqual(
argparse.Namespace(dry_run=True,
@@ -76,6 +79,7 @@ class TestUtilityFunctions(unittest.TestCase):
force=True,
config='foo',
protocol_override='sso',
caffeinate=False,
props=['--some-param=1', '--bar=2']), response)
@mock.patch('os.path.exists', return_value=False)