Retry transient dependency downloads during source qualification
Device Core qualification / qualify (push) Successful in 6m3s
Device Core qualification / qualify (push) Successful in 6m3s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
@@ -107,6 +109,52 @@ class QualificationTests(unittest.TestCase):
|
||||
CI.qualify(self.root, self.commit, {}, report)
|
||||
self.assertEqual(json.loads(report.read_text())["sourceCommit"], "old")
|
||||
|
||||
def test_network_install_error_recovers_using_the_same_frozen_command(self):
|
||||
failure = subprocess.CalledProcessError(152, "npm", output="npm error code ECONNRESET\n")
|
||||
with mock.patch.object(CI, "run", side_effect=[failure, "installed\n"]) as execute, \
|
||||
mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||
CI.install_dependencies(self.root)
|
||||
self.assertEqual(execute.call_count, 2)
|
||||
self.assertEqual(execute.call_args_list[0], execute.call_args_list[1])
|
||||
self.assertEqual(execute.call_args.args[0], ["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"])
|
||||
pause.assert_called_once_with(5)
|
||||
|
||||
def test_permanent_mixed_and_unclassified_install_failures_never_retry(self):
|
||||
for output in ("npm error code EINTEGRITY\n", "npm error code E401\n",
|
||||
"npm error code EUSAGE\n", "download ECONNRESET in explanatory text\n",
|
||||
"npm error code ECONNRESET\nnpm error code E403\n", ""):
|
||||
with self.subTest(output=output), mock.patch.object(
|
||||
CI, "run", side_effect=subprocess.CalledProcessError(1, "npm", output=output)
|
||||
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
CI.install_dependencies(self.root)
|
||||
execute.assert_called_once()
|
||||
pause.assert_not_called()
|
||||
|
||||
def test_install_retries_are_bounded_and_do_not_publish_a_report(self):
|
||||
report = self.root.parent / "result.json"
|
||||
failure = subprocess.CalledProcessError(1, "npm", output="npm error code ETIMEDOUT\n")
|
||||
with mock.patch.object(CI, "verify_sources"), mock.patch.object(
|
||||
CI, "run", side_effect=["v22.21.0\n", "10.9.4\n", failure, failure, failure]
|
||||
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
CI.qualify(self.root, self.commit, {"node": "v22.21.0", "npm": "10.9.4"}, report)
|
||||
self.assertEqual(execute.call_count, 5)
|
||||
self.assertEqual(pause.call_args_list, [mock.call(5), mock.call(10)])
|
||||
self.assertFalse(report.exists())
|
||||
|
||||
def test_build_failure_is_not_retried_as_an_install(self):
|
||||
report = self.root.parent / "result.json"
|
||||
failure = subprocess.CalledProcessError(1, "npm", output="npm error code ECONNRESET\n")
|
||||
with mock.patch.object(CI, "verify_sources"), mock.patch.object(
|
||||
CI, "run", side_effect=["v22.21.0\n", "10.9.4\n", "installed\n", failure]
|
||||
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
CI.qualify(self.root, self.commit, {"node": "v22.21.0", "npm": "10.9.4"}, report)
|
||||
self.assertEqual(execute.call_count, 4)
|
||||
pause.assert_not_called()
|
||||
self.assertFalse(report.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user