Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f67ff9e

Browse files
authored
gh-130727: Retry test_wmi on TimeoutError (#130832)
Use sleeping_retry() in test_wmi to retry multiple times on TimeoutError. Wait up to LONG_TIMEOUT seconds (5 minutes by default).
1 parent 1d251b8 commit f67ff9e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Lib/test/test_wmi.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import time
55
import unittest
6-
from test.support import import_helper, requires_resource, LOOPBACK_TIMEOUT
6+
from test import support
7+
from test.support import import_helper
78

89

910
# Do this first so test will be skipped if module doesn't exist
@@ -12,15 +13,16 @@
1213

1314
def wmi_exec_query(query):
1415
# gh-112278: WMI maybe slow response when first call.
15-
try:
16-
return _wmi.exec_query(query)
17-
except BrokenPipeError:
18-
pass
19-
except WindowsError as e:
20-
if e.winerror != 258:
21-
raise
22-
time.sleep(LOOPBACK_TIMEOUT)
23-
return _wmi.exec_query(query)
16+
for _ in support.sleeping_retry(support.LONG_TIMEOUT):
17+
try:
18+
return _wmi.exec_query(query)
19+
except BrokenPipeError:
20+
pass
21+
# retry on pipe error
22+
except WindowsError as exc:
23+
if exc.winerror != 258:
24+
raise
25+
# retry on timeout
2426

2527

2628
class WmiTests(unittest.TestCase):
@@ -58,7 +60,7 @@ def test_wmi_query_not_select(self):
5860
with self.assertRaises(ValueError):
5961
wmi_exec_query("not select, just in case someone tries something")
6062

61-
@requires_resource('cpu')
63+
@support.requires_resource('cpu')
6264
def test_wmi_query_overflow(self):
6365
# Ensure very big queries fail
6466
# Test multiple times to ensure consistency

0 commit comments

Comments
 (0)