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

Fixing randomly failing test #3437

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions tests/test_asyncio/test_hash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import math
from datetime import datetime, timedelta

from tests.conftest import skip_if_server_version_lt
Expand Down Expand Up @@ -128,9 +129,9 @@ async def test_hpexpire_multiple_fields(r):
async def test_hexpireat_basic(r):
await r.delete("test:hash")
await r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
assert await r.hexpireat("test:hash", exp_time, "field1") == [1]
await asyncio.sleep(1.1)
await asyncio.sleep(2.1)
assert await r.hexists("test:hash", "field1") is False
assert await r.hexists("test:hash", "field2") is True

Expand All @@ -139,9 +140,9 @@ async def test_hexpireat_basic(r):
async def test_hexpireat_with_datetime(r):
await r.delete("test:hash")
await r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
exp_time = datetime.now() + timedelta(seconds=1)
exp_time = (datetime.now() + timedelta(seconds=2)).replace(microsecond=0)
assert await r.hexpireat("test:hash", exp_time, "field1") == [1]
await asyncio.sleep(1.1)
await asyncio.sleep(2.1)
assert await r.hexists("test:hash", "field1") is False
assert await r.hexists("test:hash", "field2") is True

Expand Down Expand Up @@ -175,9 +176,9 @@ async def test_hexpireat_multiple_fields(r):
"test:hash",
mapping={"field1": "value1", "field2": "value2", "field3": "value3"},
)
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
assert await r.hexpireat("test:hash", exp_time, "field1", "field2") == [1, 1]
await asyncio.sleep(1.5)
await asyncio.sleep(2.1)
assert await r.hexists("test:hash", "field1") is False
assert await r.hexists("test:hash", "field2") is False
assert await r.hexists("test:hash", "field3") is True
Expand Down
13 changes: 7 additions & 6 deletions tests/test_hash.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import time
from datetime import datetime, timedelta

Expand Down Expand Up @@ -147,9 +148,9 @@ def test_hpexpire_multiple_condition_flags_error(r):
def test_hexpireat_basic(r):
r.delete("test:hash")
r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
assert r.hexpireat("test:hash", exp_time, "field1") == [1]
time.sleep(1.1)
time.sleep(2.1)
assert r.hexists("test:hash", "field1") is False
assert r.hexists("test:hash", "field2") is True

Expand All @@ -158,9 +159,9 @@ def test_hexpireat_basic(r):
def test_hexpireat_with_datetime(r):
r.delete("test:hash")
r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
exp_time = datetime.now() + timedelta(seconds=1)
exp_time = (datetime.now() + timedelta(seconds=2)).replace(microsecond=0)
assert r.hexpireat("test:hash", exp_time, "field1") == [1]
time.sleep(1.1)
time.sleep(2.1)
assert r.hexists("test:hash", "field1") is False
assert r.hexists("test:hash", "field2") is True

Expand Down Expand Up @@ -194,9 +195,9 @@ def test_hexpireat_multiple_fields(r):
"test:hash",
mapping={"field1": "value1", "field2": "value2", "field3": "value3"},
)
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
assert r.hexpireat("test:hash", exp_time, "field1", "field2") == [1, 1]
time.sleep(1.1)
time.sleep(2.1)
assert r.hexists("test:hash", "field1") is False
assert r.hexists("test:hash", "field2") is False
assert r.hexists("test:hash", "field3") is True
Expand Down
Loading