Skip to content

Commit 9acc965

Browse files
test-my-pr robustification (#4756)
* Add try_retry-logic to get_packages_count() Occasionally, get_packages_count() fails, which is a bit annoying since it happens after compilation and therefore can take some time to detect. Add try-retry to the function to make it more robust. * Move try_retry-logic to lib.get_package() Moving it to the library means test-my-pr also benefits from it. This fixes Trac ticket #11405.
1 parent d3e7566 commit 9acc965

2 files changed

Lines changed: 30 additions & 24 deletions

File tree

tools/donate-cpu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
package = package_urls[packages_processed-1]
204204
else:
205205
try:
206-
package = lib.try_retry(lib.get_package, max_tries=3, sleep_duration=30.0, sleep_factor=1.0)
206+
package = lib.get_package()
207207
except Exception as e:
208208
print('Error: Failed to get package ({}), retry later'.format(e))
209209
sys.exit(1)

tools/donate_cpu_lib.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
1616
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
1717
# changes)
18-
CLIENT_VERSION = "1.3.42"
18+
CLIENT_VERSION = "1.3.43"
1919

2020
# Timeout for analysis with Cppcheck in seconds
2121
CPPCHECK_TIMEOUT = 30 * 60
@@ -253,31 +253,37 @@ def get_cppcheck_versions():
253253

254254

255255
def get_packages_count():
256-
print('Connecting to server to get count of packages..')
257-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
258-
sock.connect(__server_address)
259-
sock.send(b'getPackagesCount\n')
260-
packages = sock.recv(64)
261-
# TODO: sock.recv() sometimes hangs and returns b'' afterwards
262-
if not packages:
263-
raise Exception('received empty response')
264-
return int(packages)
256+
def __get_packages_count():
257+
print('Connecting to server to get count of packages..')
258+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
259+
sock.connect(__server_address)
260+
sock.send(b'getPackagesCount\n')
261+
packages = sock.recv(64)
262+
# TODO: sock.recv() sometimes hangs and returns b'' afterwards
263+
if not packages:
264+
raise Exception('received empty response')
265+
return int(packages)
266+
267+
return try_retry(__get_packages_count)
265268

266269

267270
def get_package(package_index=None):
268-
print('Connecting to server to get assigned work..')
269-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
270-
sock.connect(__server_address)
271-
if package_index is None:
272-
sock.send(b'get\n')
273-
else:
274-
request = 'getPackageIdx:' + str(package_index) + '\n'
275-
sock.send(request.encode())
276-
package = sock.recv(256)
277-
# TODO: sock.recv() sometimes hangs and returns b'' afterwards
278-
if not package:
279-
raise Exception('received empty response')
280-
return package.decode('utf-8')
271+
def __get_package(package_index):
272+
print('Connecting to server to get assigned work..')
273+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
274+
sock.connect(__server_address)
275+
if package_index is None:
276+
sock.send(b'get\n')
277+
else:
278+
request = 'getPackageIdx:' + str(package_index) + '\n'
279+
sock.send(request.encode())
280+
package = sock.recv(256)
281+
# TODO: sock.recv() sometimes hangs and returns b'' afterwards
282+
if not package:
283+
raise Exception('received empty response')
284+
return package.decode('utf-8')
285+
286+
return try_retry(__get_package, fargs=(package_index,), max_tries=3, sleep_duration=30.0, sleep_factor=1.0)
281287

282288

283289
def __handle_remove_readonly(func, path, exc):

0 commit comments

Comments
 (0)