diff --git a/tests/test_asyncio/test_hash.py b/tests/test_asyncio/test_hash.py index 8d94799fbb..15e426673b 100644 --- a/tests/test_asyncio/test_hash.py +++ b/tests/test_asyncio/test_hash.py @@ -1,4 +1,5 @@ import asyncio +import math from datetime import datetime, timedelta from tests.conftest import skip_if_server_version_lt @@ -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 @@ -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 @@ -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 diff --git a/tests/test_hash.py b/tests/test_hash.py index 9ed5e98132..0422185865 100644 --- a/tests/test_hash.py +++ b/tests/test_hash.py @@ -1,3 +1,4 @@ +import math import time from datetime import datetime, timedelta @@ -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 @@ -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 @@ -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