mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[BE][GHF] Add retries_decorator
(#101227)
I've noticed that 3-4 functions in trymerge are trying to implement similar tail recursion for flaky network retries. Unify them using single wrapper in `gitutils.py` <!-- copilot:poem --> ### <samp>🤖 Generated by Copilot at 8d40631</samp> > _`retries_decorator`_ > _adds resilience to GitHub scripts_ > _autumn of errors_ Pull Request resolved: https://github.com/pytorch/pytorch/pull/101227 Approved by: https://github.com/kit1980
This commit is contained in:
committed by
PyTorch MergeBot
parent
2fcc2002fa
commit
568bac7961
17
.github/scripts/test_gitutils.py
vendored
17
.github/scripts/test_gitutils.py
vendored
@ -8,6 +8,7 @@ from gitutils import (
|
||||
GitRepo,
|
||||
patterns_to_regex,
|
||||
PeekableIterator,
|
||||
retries_decorator,
|
||||
)
|
||||
|
||||
|
||||
@ -49,6 +50,22 @@ class TestPattern(TestCase):
|
||||
self.assertTrue(patterns_re.match(filename))
|
||||
|
||||
|
||||
class TestRetriesDecorator(TestCase):
|
||||
def test_simple(self) -> None:
|
||||
@retries_decorator()
|
||||
def foo(x: int, y: int) -> int:
|
||||
return x + y
|
||||
|
||||
self.assertEqual(foo(3, 4), 7)
|
||||
|
||||
def test_fails(self) -> None:
|
||||
@retries_decorator(rc=0)
|
||||
def foo(x: int, y: int) -> int:
|
||||
return x + y
|
||||
|
||||
self.assertEqual(foo("a", 4), 0)
|
||||
|
||||
|
||||
class TestGitRepo(TestCase):
|
||||
def setUp(self) -> None:
|
||||
repo_dir = BASE_DIR.parent.parent.absolute()
|
||||
|
Reference in New Issue
Block a user