Skip to content

Commit b83f9ba

Browse files
committed
try again
1 parent 45efac9 commit b83f9ba

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

test/asynchronous/unified_format.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ def maybe_skip_test(self, spec):
533533
class_name = self.__class__.__name__.lower()
534534
description = spec["description"].lower()
535535
if "csot" in class_name:
536+
if "gridfs" in class_name and sys.platform == "win32":
537+
self.skipTest("PYTHON-3522 CSOT GridFS tests are flaky on Windows")
538+
if (
539+
"Non-tailable cursor lifetime remaining timeoutMS applied to getMore if timeoutMode is unset"
540+
in description
541+
and sys.platform != "linux"
542+
):
543+
self.skipTest("PYTHON-3522 CSOT test is flaky on Windows and MacOS")
536544
if async_client_context.storage_engine == "mmapv1":
537545
self.skipTest(
538546
"MMAPv1 does not support retryable writes which is required for CSOT tests"
@@ -1380,8 +1388,6 @@ async def run_scenario(self, spec, uri=None):
13801388
if re.match(flaky_test, self.id()) is not None:
13811389
func_name = self.id()
13821390
options = dict(reset_func=self.asyncSetUp, func_name=func_name)
1383-
if "csot" in func_name:
1384-
options["max_runs"] = 3
13851391
decorator = flaky(**options)
13861392
await decorator(self._run_scenario)(spec, uri)
13871393
return

test/asynchronous/utils.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import asyncio
1919
import contextlib
20+
import os
2021
import random
2122
import sys
2223
import threading # Used in the synchronized version of this file
@@ -168,43 +169,40 @@ def flaky(
168169
reset_func=None,
169170
):
170171
is_cpython_linux = sys.platform == "linux" and sys.implementation.name == "cpython"
171-
if is_cpython_linux and not affects_cpython_linux:
172+
disable_flaky = "DISABLE_FLAKY" in os.environ
173+
if disable_flaky or (is_cpython_linux and not affects_cpython_linux):
172174
max_runs = 1
173175
min_passes = 1
174176

175177
def decorator(target_func):
176178
@wraps(target_func)
177179
async def wrapper(*args, **kwargs):
178180
passes = 0
179-
failure = None
180181
for i in range(max_runs):
181182
try:
182183
result = await target_func(*args, **kwargs)
183184
passes += 1
184185
if passes == min_passes:
185186
return result
186187
except Exception as e:
187-
failure = e
188-
await asyncio.sleep(delay)
189-
if failure is not None and i < max_runs - 1:
188+
if i == max_runs - 1:
189+
raise e
190190
print(
191191
f"Retrying after attempt {i+1} of {func_name or target_func.__name__} failed with:\n"
192192
f"{traceback.format_exc()}",
193193
file=sys.stderr,
194194
)
195+
await asyncio.sleep(delay)
195196
if reset_func:
196197
await reset_func()
197-
if failure:
198-
raise failure
199-
raise RuntimeError(f"Only passed {passes} of {min_passes} times")
200198

201199
return wrapper
202200

203-
# If `func` is callable, the decorator was used without arguments (`@flaky`)
201+
# If `func` is callable, the decorator was used without arguments (`@flaky`).
204202
if callable(func):
205203
return decorator(func)
206204

207-
# Otherwise, return the decorator function, allowing arguments (`@flaky(max_runs=...)`)
205+
# Otherwise, return the decorator function, allowing arguments (`@flaky(max_runs=...)`).
208206
return decorator
209207

210208

test/unified_format.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ def maybe_skip_test(self, spec):
532532
class_name = self.__class__.__name__.lower()
533533
description = spec["description"].lower()
534534
if "csot" in class_name:
535+
if "gridfs" in class_name and sys.platform == "win32":
536+
self.skipTest("PYTHON-3522 CSOT GridFS tests are flaky on Windows")
537+
if (
538+
"Non-tailable cursor lifetime remaining timeoutMS applied to getMore if timeoutMode is unset"
539+
in description
540+
and sys.platform != "linux"
541+
):
542+
self.skipTest("PYTHON-3522 CSOT test is flaky on Windows and MacOS")
535543
if client_context.storage_engine == "mmapv1":
536544
self.skipTest(
537545
"MMAPv1 does not support retryable writes which is required for CSOT tests"
@@ -1367,8 +1375,6 @@ def run_scenario(self, spec, uri=None):
13671375
if re.match(flaky_test, self.id()) is not None:
13681376
func_name = self.id()
13691377
options = dict(reset_func=self.setUp, func_name=func_name)
1370-
if "csot" in func_name:
1371-
options["max_runs"] = 3
13721378
decorator = flaky(**options)
13731379
decorator(self._run_scenario)(spec, uri)
13741380
return

test/utils.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import asyncio
1919
import contextlib
20+
import os
2021
import random
2122
import sys
2223
import threading # Used in the synchronized version of this file
@@ -166,43 +167,40 @@ def flaky(
166167
reset_func=None,
167168
):
168169
is_cpython_linux = sys.platform == "linux" and sys.implementation.name == "cpython"
169-
if is_cpython_linux and not affects_cpython_linux:
170+
disable_flaky = "DISABLE_FLAKY" in os.environ
171+
if disable_flaky or (is_cpython_linux and not affects_cpython_linux):
170172
max_runs = 1
171173
min_passes = 1
172174

173175
def decorator(target_func):
174176
@wraps(target_func)
175177
def wrapper(*args, **kwargs):
176178
passes = 0
177-
failure = None
178179
for i in range(max_runs):
179180
try:
180181
result = target_func(*args, **kwargs)
181182
passes += 1
182183
if passes == min_passes:
183184
return result
184185
except Exception as e:
185-
failure = e
186-
time.sleep(delay)
187-
if failure is not None and i < max_runs - 1:
186+
if i == max_runs - 1:
187+
raise e
188188
print(
189189
f"Retrying after attempt {i+1} of {func_name or target_func.__name__} failed with:\n"
190190
f"{traceback.format_exc()}",
191191
file=sys.stderr,
192192
)
193+
time.sleep(delay)
193194
if reset_func:
194195
reset_func()
195-
if failure:
196-
raise failure
197-
raise RuntimeError(f"Only passed {passes} of {min_passes} times")
198196

199197
return wrapper
200198

201-
# If `func` is callable, the decorator was used without arguments (`@flaky`)
199+
# If `func` is callable, the decorator was used without arguments (`@flaky`).
202200
if callable(func):
203201
return decorator(func)
204202

205-
# Otherwise, return the decorator function, allowing arguments (`@flaky(max_runs=...)`)
203+
# Otherwise, return the decorator function, allowing arguments (`@flaky(max_runs=...)`).
206204
return decorator
207205

208206

0 commit comments

Comments
 (0)