Skip to content

Commit dd5edc2

Browse files
committed
Always rounding up to avoid randomly failing tests
1 parent ebf070a commit dd5edc2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/test_hash.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import time
23
from datetime import datetime, timedelta
34

@@ -147,9 +148,9 @@ def test_hpexpire_multiple_condition_flags_error(r):
147148
def test_hexpireat_basic(r):
148149
r.delete("test:hash")
149150
r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
150-
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
151+
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
151152
assert r.hexpireat("test:hash", exp_time, "field1") == [1]
152-
time.sleep(1.1)
153+
time.sleep(2.1)
153154
assert r.hexists("test:hash", "field1") is False
154155
assert r.hexists("test:hash", "field2") is True
155156

@@ -158,9 +159,9 @@ def test_hexpireat_basic(r):
158159
def test_hexpireat_with_datetime(r):
159160
r.delete("test:hash")
160161
r.hset("test:hash", mapping={"field1": "value1", "field2": "value2"})
161-
exp_time = datetime.now() + timedelta(seconds=1)
162+
exp_time = (datetime.now() + timedelta(seconds=2)).replace(microsecond=0)
162163
assert r.hexpireat("test:hash", exp_time, "field1") == [1]
163-
time.sleep(1.1)
164+
time.sleep(2.1)
164165
assert r.hexists("test:hash", "field1") is False
165166
assert r.hexists("test:hash", "field2") is True
166167

@@ -194,9 +195,9 @@ def test_hexpireat_multiple_fields(r):
194195
"test:hash",
195196
mapping={"field1": "value1", "field2": "value2", "field3": "value3"},
196197
)
197-
exp_time = int((datetime.now() + timedelta(seconds=1)).timestamp())
198+
exp_time = math.ceil((datetime.now() + timedelta(seconds=1)).timestamp())
198199
assert r.hexpireat("test:hash", exp_time, "field1", "field2") == [1, 1]
199-
time.sleep(1.1)
200+
time.sleep(2.1)
200201
assert r.hexists("test:hash", "field1") is False
201202
assert r.hexists("test:hash", "field2") is False
202203
assert r.hexists("test:hash", "field3") is True

0 commit comments

Comments
 (0)