mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[3.13] gh-130727: Retry test_wmi on TimeoutError (GH-130832) (#130839)
gh-130727: Retry test_wmi on TimeoutError (GH-130832)
Use sleeping_retry() in test_wmi to retry multiple times on
TimeoutError. Wait up to LONG_TIMEOUT seconds (5 minutes by default).
(cherry picked from commit f67ff9e820
)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
418021e229
commit
a115480f71
1 changed files with 13 additions and 11 deletions
|
@ -3,7 +3,8 @@
|
|||
|
||||
import time
|
||||
import unittest
|
||||
from test.support import import_helper, requires_resource, LOOPBACK_TIMEOUT
|
||||
from test import support
|
||||
from test.support import import_helper
|
||||
|
||||
|
||||
# Do this first so test will be skipped if module doesn't exist
|
||||
|
@ -12,15 +13,16 @@ _wmi = import_helper.import_module('_wmi', required_on=['win'])
|
|||
|
||||
def wmi_exec_query(query):
|
||||
# gh-112278: WMI maybe slow response when first call.
|
||||
try:
|
||||
return _wmi.exec_query(query)
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
except WindowsError as e:
|
||||
if e.winerror != 258:
|
||||
raise
|
||||
time.sleep(LOOPBACK_TIMEOUT)
|
||||
return _wmi.exec_query(query)
|
||||
for _ in support.sleeping_retry(support.LONG_TIMEOUT):
|
||||
try:
|
||||
return _wmi.exec_query(query)
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
# retry on pipe error
|
||||
except WindowsError as exc:
|
||||
if exc.winerror != 258:
|
||||
raise
|
||||
# retry on timeout
|
||||
|
||||
|
||||
class WmiTests(unittest.TestCase):
|
||||
|
@ -58,7 +60,7 @@ class WmiTests(unittest.TestCase):
|
|||
with self.assertRaises(ValueError):
|
||||
wmi_exec_query("not select, just in case someone tries something")
|
||||
|
||||
@requires_resource('cpu')
|
||||
@support.requires_resource('cpu')
|
||||
def test_wmi_query_overflow(self):
|
||||
# Ensure very big queries fail
|
||||
# Test multiple times to ensure consistency
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue