1
1
import asyncio
2
+ import math
2
3
from datetime import datetime , timedelta
3
4
4
5
from tests .conftest import skip_if_server_version_lt
@@ -128,9 +129,9 @@ async def test_hpexpire_multiple_fields(r):
128
129
async def test_hexpireat_basic (r ):
129
130
await r .delete ("test:hash" )
130
131
await r .hset ("test:hash" , mapping = {"field1" : "value1" , "field2" : "value2" })
131
- exp_time = int ((datetime .now () + timedelta (seconds = 1 )).timestamp ())
132
+ exp_time = math . ceil ((datetime .now () + timedelta (seconds = 1 )).timestamp ())
132
133
assert await r .hexpireat ("test:hash" , exp_time , "field1" ) == [1 ]
133
- await asyncio .sleep (1 .1 )
134
+ await asyncio .sleep (2 .1 )
134
135
assert await r .hexists ("test:hash" , "field1" ) is False
135
136
assert await r .hexists ("test:hash" , "field2" ) is True
136
137
@@ -139,9 +140,9 @@ async def test_hexpireat_basic(r):
139
140
async def test_hexpireat_with_datetime (r ):
140
141
await r .delete ("test:hash" )
141
142
await r .hset ("test:hash" , mapping = {"field1" : "value1" , "field2" : "value2" })
142
- exp_time = datetime .now () + timedelta (seconds = 1 )
143
+ exp_time = ( datetime .now () + timedelta (seconds = 2 )). replace ( microsecond = 0 )
143
144
assert await r .hexpireat ("test:hash" , exp_time , "field1" ) == [1 ]
144
- await asyncio .sleep (1 .1 )
145
+ await asyncio .sleep (2 .1 )
145
146
assert await r .hexists ("test:hash" , "field1" ) is False
146
147
assert await r .hexists ("test:hash" , "field2" ) is True
147
148
@@ -175,9 +176,9 @@ async def test_hexpireat_multiple_fields(r):
175
176
"test:hash" ,
176
177
mapping = {"field1" : "value1" , "field2" : "value2" , "field3" : "value3" },
177
178
)
178
- exp_time = int ((datetime .now () + timedelta (seconds = 1 )).timestamp ())
179
+ exp_time = math . ceil ((datetime .now () + timedelta (seconds = 1 )).timestamp ())
179
180
assert await r .hexpireat ("test:hash" , exp_time , "field1" , "field2" ) == [1 , 1 ]
180
- await asyncio .sleep (1.5 )
181
+ await asyncio .sleep (2.1 )
181
182
assert await r .hexists ("test:hash" , "field1" ) is False
182
183
assert await r .hexists ("test:hash" , "field2" ) is False
183
184
assert await r .hexists ("test:hash" , "field3" ) is True
0 commit comments