diff options
author | dvora-h <67596500+dvora-h@users.noreply.github.com> | 2023-01-05 14:33:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 14:33:10 +0200 |
commit | e67d15c490585de3f350b91ee9a4e12d3ba134b7 (patch) | |
tree | 97edd622ca5c147fd3d7878a11c7b5ace427d3e6 /tests/test_asyncio | |
parent | f14ed1fc822a88a21bbfc64e36bf8b09e5c9386c (diff) | |
download | redis-py-e67d15c490585de3f350b91ee9a4e12d3ba134b7.tar.gz |
replase get_event_loop wite get_running_loop (#2530)
Diffstat (limited to 'tests/test_asyncio')
-rw-r--r-- | tests/test_asyncio/test_connection_pool.py | 14 | ||||
-rw-r--r-- | tests/test_asyncio/test_lock.py | 4 | ||||
-rw-r--r-- | tests/test_asyncio/test_pubsub.py | 12 |
3 files changed, 15 insertions, 15 deletions
diff --git a/tests/test_asyncio/test_connection_pool.py b/tests/test_asyncio/test_connection_pool.py index 5de25f2..d1e52bd 100644 --- a/tests/test_asyncio/test_connection_pool.py +++ b/tests/test_asyncio/test_connection_pool.py @@ -243,11 +243,11 @@ class TestBlockingConnectionPool: ) as pool: c1 = await pool.get_connection("_") - start = asyncio.get_event_loop().time() + start = asyncio.get_running_loop().time() with pytest.raises(redis.ConnectionError): await pool.get_connection("_") # we should have waited at least 0.1 seconds - assert asyncio.get_event_loop().time() - start >= 0.1 + assert asyncio.get_running_loop().time() - start >= 0.1 await c1.disconnect() async def test_connection_pool_blocks_until_conn_available(self, master_host): @@ -265,9 +265,9 @@ class TestBlockingConnectionPool: await asyncio.sleep(0.1) await pool.release(c1) - start = asyncio.get_event_loop().time() + start = asyncio.get_running_loop().time() await asyncio.gather(target(), pool.get_connection("_")) - assert asyncio.get_event_loop().time() - start >= 0.1 + assert asyncio.get_running_loop().time() - start >= 0.1 async def test_reuse_previously_released_connection(self, master_host): connection_kwargs = {"host": master_host} @@ -668,12 +668,12 @@ class TestHealthCheck: await redis.flushall() def assert_interval_advanced(self, connection): - diff = connection.next_health_check - asyncio.get_event_loop().time() + diff = connection.next_health_check - asyncio.get_running_loop().time() assert self.interval >= diff > (self.interval - 1) async def test_health_check_runs(self, r): if r.connection: - r.connection.next_health_check = asyncio.get_event_loop().time() - 1 + r.connection.next_health_check = asyncio.get_running_loop().time() - 1 await r.connection.check_health() self.assert_interval_advanced(r.connection) @@ -681,7 +681,7 @@ class TestHealthCheck: # invoke a command to make sure the connection is entirely setup if r.connection: await r.get("foo") - r.connection.next_health_check = asyncio.get_event_loop().time() + r.connection.next_health_check = asyncio.get_running_loop().time() with mock.patch.object( r.connection, "send_command", wraps=r.connection.send_command ) as m: diff --git a/tests/test_asyncio/test_lock.py b/tests/test_asyncio/test_lock.py index 15c3ec5..d78f741 100644 --- a/tests/test_asyncio/test_lock.py +++ b/tests/test_asyncio/test_lock.py @@ -136,11 +136,11 @@ class TestLock: sleep = 60 bt = 1 lock2 = self.get_lock(r, "foo", sleep=sleep, blocking_timeout=bt) - start = asyncio.get_event_loop().time() + start = asyncio.get_running_loop().time() assert not await lock2.acquire() # the elapsed timed is less than the blocking_timeout as the lock is # unattainable given the sleep/blocking_timeout configuration - assert bt > (asyncio.get_event_loop().time() - start) + assert bt > (asyncio.get_running_loop().time() - start) await lock1.release() async def test_releasing_unlocked_lock_raises_error(self, r): diff --git a/tests/test_asyncio/test_pubsub.py b/tests/test_asyncio/test_pubsub.py index 37b7206..c2a9130 100644 --- a/tests/test_asyncio/test_pubsub.py +++ b/tests/test_asyncio/test_pubsub.py @@ -30,7 +30,7 @@ def with_timeout(t): async def wait_for_message(pubsub, timeout=0.2, ignore_subscribe_messages=False): - now = asyncio.get_event_loop().time() + now = asyncio.get_running_loop().time() timeout = now + timeout while now < timeout: message = await pubsub.get_message( @@ -39,7 +39,7 @@ async def wait_for_message(pubsub, timeout=0.2, ignore_subscribe_messages=False) if message is not None: return message await asyncio.sleep(0.01) - now = asyncio.get_event_loop().time() + now = asyncio.get_running_loop().time() return None @@ -675,7 +675,7 @@ class TestPubSubReconnect: await messages.put(message) break - task = asyncio.get_event_loop().create_task(loop()) + task = asyncio.get_running_loop().create_task(loop()) # get the initial connect message async with async_timeout.timeout(1): message = await messages.get() @@ -724,7 +724,7 @@ class TestPubSubRun: messages = asyncio.Queue() p = pubsub await self._subscribe(p, foo=callback) - task = asyncio.get_event_loop().create_task(p.run()) + task = asyncio.get_running_loop().create_task(p.run()) await r.publish("foo", "bar") message = await messages.get() task.cancel() @@ -748,7 +748,7 @@ class TestPubSubRun: p = pubsub await self._subscribe(p, foo=lambda x: None) with mock.patch.object(p, "get_message", side_effect=Exception("error")): - task = asyncio.get_event_loop().create_task( + task = asyncio.get_running_loop().create_task( p.run(exception_handler=exception_handler_callback) ) e = await exceptions.get() @@ -765,7 +765,7 @@ class TestPubSubRun: messages = asyncio.Queue() p = pubsub - task = asyncio.get_event_loop().create_task(p.run()) + task = asyncio.get_running_loop().create_task(p.run()) # wait until loop gets settled. Add a subscription await asyncio.sleep(0.1) await p.subscribe(foo=callback) |