Skip to content

Commit

Permalink
Merge pull request #89 from valkey-io/aiven-sal/flaky
Browse files Browse the repository at this point in the history
tests: completely remove flaky tests
  • Loading branch information
aiven-sal authored Sep 9, 2024
2 parents 0941032 + b2e9569 commit 1c6ce95
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
5 changes: 2 additions & 3 deletions tests/test_asyncio/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ async def test_blocking(self, r):
async def test_blocking_timeout(self, r):
lock1 = self.get_lock(r, "foo")
assert await lock1.acquire(blocking=False)
bt = 0.9
bt = 0.2
sleep = 0.05
lock2 = self.get_lock(r, "foo", sleep=sleep, blocking_timeout=bt)
start = asyncio.get_running_loop().time()
assert not await lock2.acquire()
# The elapsed duration should be less than the total blocking_timeout
assert bt >= (asyncio.get_running_loop().time() - start) > bt - sleep
assert (asyncio.get_running_loop().time() - start) > (bt - sleep)
await lock1.release()

async def test_context_manager(self, r):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ def test_blocking_timeout(self, r):
assert lock1.acquire(blocking=False)
bt = 0.4
sleep = 0.05
fudge_factor = 0.5
lock2 = self.get_lock(r, "foo", sleep=sleep, blocking_timeout=bt)
start = time.monotonic()
assert not lock2.acquire()
# The elapsed duration should be less than the total blocking_timeout
assert (bt + fudge_factor) > (time.monotonic() - start) > bt - sleep
assert (time.monotonic() - start) > (bt - sleep)
lock1.release()

def test_context_manager(self, r):
Expand All @@ -120,12 +118,10 @@ def test_context_manager_blocking_timeout(self, r):
with self.get_lock(r, "foo", blocking=False):
bt = 0.4
sleep = 0.05
fudge_factor = 0.5
lock2 = self.get_lock(r, "foo", sleep=sleep, blocking_timeout=bt)
start = time.monotonic()
assert not lock2.acquire()
# The elapsed duration should be less than the total blocking_timeout
assert (bt + fudge_factor) > (time.monotonic() - start) > bt - sleep
assert (time.monotonic() - start) > (bt - sleep)

def test_context_manager_raises_when_locked_not_acquired(self, r):
r.set("foo", "bar")
Expand Down

0 comments on commit 1c6ce95

Please sign in to comment.