Skip to content

Commit fe3d46d

Browse files
committed
Attempt to make scheduler tests less flaky
Some of the scheduler tests are really flaky. My suspicion is that it might stem from the `MockFunction` not being thread safe, so two calls at the same time might cause issues with the total count
1 parent cdf870f commit fe3d46d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tests/test_unstable/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from collections.abc import Generator
3+
from threading import RLock
34
from time import sleep, time
45
from uuid import uuid4
56

@@ -38,11 +39,12 @@ def set_client() -> CogniteClient:
3839
class MockFunction:
3940
def __init__(self, sleep_time: int) -> None:
4041
self.called_times: list[float] = []
41-
4242
self.sleep_time = sleep_time
43+
self.lock = RLock()
4344

4445
def __call__(self) -> None:
45-
self.called_times.append(time())
46+
with self.lock:
47+
self.called_times.append(time())
4648
sleep(self.sleep_time)
4749

4850

0 commit comments

Comments
 (0)