Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to make tests less flaky on windows. #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions once_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

# This is a "large" number of workers to schedule function calls in parallel.
_N_WORKERS = 32
# The default is for thread switching to occur every 5ms. Because most of the
# threads in these tests are worst-case stress tests that have very little to
# do and are often blocked, we set the threads to switch a bit quicker just so
# tests can go a bit quicker.
if sys.getswitchinterval() > 0.0001:
sys.setswitchinterval(0.0001)


class WrappedException:
Expand Down Expand Up @@ -103,11 +109,13 @@ def __init__(self) -> None:
self.value = 0
self.ready = threading.Event()
self.ready.set()
self._lock = threading.Lock()

def get_incremented(self) -> int:
self.ready.wait()
self.value += 1
return self.value
with self._lock:
self.value += 1
return self.value


def execute_with_barrier(*args, n_workers=None, is_async=False):
Expand Down Expand Up @@ -834,9 +842,9 @@ def run(self) -> int:
b_job = executor.submit(b.run)
# The b_job will deadlock and this will fail if different
# object executions block each other.
self.assertEqual(b_job.result(timeout=5), 1)
self.assertEqual(b_job.result(timeout=15), 1)
a.counter.ready.set()
self.assertEqual(a_job.result(timeout=5), 1)
self.assertEqual(a_job.result(timeout=15), 1)

def test_once_per_instance_parallel(self):
class _CallOnceClass(Counter):
Expand Down