From f27079ab4f7b0e45053875c3f751698bc8438b69 Mon Sep 17 00:00:00 2001 From: Ilian Iliev Date: Sun, 24 Nov 2024 18:03:40 +0200 Subject: [PATCH] Always rounding up to avoid randomly failing tests --- tests/test_hash.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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