From df66a34f68f4b2f2c08039f178d267c7dafd9d59 Mon Sep 17 00:00:00 2001 From: katthomas Date: Tue, 11 Oct 2016 16:55:15 -0700 Subject: [PATCH] Remove git lockfile flakiness on win (bot_update) Hypothesis: Sometimes bot update fails because windows fails to delete a lockfile associated with a git process. Test: If this happens, let's delete that lockfile and try again. BUG=651602 Review-Url: https://codereview.chromium.org/2382653005 --- recipe_modules/bot_update/resources/bot_update.py | 10 ++++++++-- tests/bot_update_coverage_test.py | 13 ++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/recipe_modules/bot_update/resources/bot_update.py b/recipe_modules/bot_update/resources/bot_update.py index ca91dbdf9..321136966 100755 --- a/recipe_modules/bot_update/resources/bot_update.py +++ b/recipe_modules/bot_update/resources/bot_update.py @@ -322,7 +322,7 @@ def gclient_configure(solutions, target_os, target_os_only, git_cache_dir): solutions, target_os, target_os_only, git_cache_dir)) -def gclient_sync(with_branch_heads, shallow): +def gclient_sync(with_branch_heads, shallow, break_repo_locks): # We just need to allocate a filename. fd, gclient_output_file = tempfile.mkstemp(suffix='.json') os.close(fd) @@ -334,6 +334,8 @@ def gclient_sync(with_branch_heads, shallow): cmd += ['--with_branch_heads'] if shallow: cmd += ['--shallow'] + if break_repo_locks: + cmd += ['--break_repo_locks'] try: call(*cmd, tries=1) @@ -753,10 +755,14 @@ def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, # Ensure our build/ directory is set up with the correct .gclient file. gclient_configure(solutions, target_os, target_os_only, git_cache_dir) + # Windows sometimes has trouble deleting files. This can make git commands + # that rely on locks fail. + break_repo_locks = True if sys.platform.startswith('win') else False # Let gclient do the DEPS syncing. # The branch-head refspec is a special case because its possible Chrome # src, which contains the branch-head refspecs, is DEPSed in. - gclient_output = gclient_sync(BRANCH_HEADS_REFSPEC in refs, shallow) + gclient_output = gclient_sync(BRANCH_HEADS_REFSPEC in refs, shallow, + break_repo_locks) # Now that gclient_sync has finished, we should revert any .DEPS.git so that # presubmit doesn't complain about it being modified. diff --git a/tests/bot_update_coverage_test.py b/tests/bot_update_coverage_test.py index f055a9ba6..9b7715e4e 100755 --- a/tests/bot_update_coverage_test.py +++ b/tests/bot_update_coverage_test.py @@ -15,7 +15,6 @@ import unittest sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'recipe_modules', 'bot_update', 'resources')) -sys.platform = 'linux2' # For consistency, ya know? import bot_update DEFAULT_PARAMS = { @@ -164,6 +163,7 @@ def fake_git(*args, **kwargs): class BotUpdateUnittests(unittest.TestCase): def setUp(self): + sys.platform = 'linux2' # For consistency, ya know? self.filesystem = FakeFilesystem() self.call = MockedCall(self.filesystem) self.gclient = MockedGclientSync(self.filesystem) @@ -195,6 +195,17 @@ class BotUpdateUnittests(unittest.TestCase): bot_update.ensure_checkout(**self.params) return self.call.records + def testBreakLocks(self): + sys.platform = 'win' + self.call.expect(('gclient.bat', 'sync')).returns(self.gclient) + bot_update.ensure_checkout(**self.params) + gclient_sync_cmd = None + for record in self.call.records: + args = record[0] + if args[0] == 'gclient.bat' and args[1] == 'sync': + gclient_sync_cmd = args + self.assertTrue('--break_repo_locks' in gclient_sync_cmd) + if __name__ == '__main__': unittest.main()