test: move wait_for_first_completed to pylib/util.py
This function is needed in a new test added in the next commit and this refactoring avoids code duplication.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
from collections.abc import Coroutine
|
||||
import threading
|
||||
import time
|
||||
import asyncio
|
||||
@@ -246,3 +247,11 @@ async def wait_for_view(cql: Session, name: str, node_count: int, timeout: int =
|
||||
return done[0][0] == node_count or None
|
||||
deadline = time.time() + timeout
|
||||
await wait_for(view_is_built, deadline)
|
||||
|
||||
|
||||
async def wait_for_first_completed(coros: list[Coroutine]):
|
||||
done, pending = await asyncio.wait([asyncio.create_task(c) for c in coros], return_when=asyncio.FIRST_COMPLETED)
|
||||
for t in pending:
|
||||
t.cancel()
|
||||
for t in done:
|
||||
await t
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#
|
||||
from test.pylib.manager_client import ManagerClient
|
||||
from test.pylib.util import wait_for_first_completed
|
||||
from test.topology.conftest import skip_mode
|
||||
from collections.abc import Coroutine
|
||||
import pytest
|
||||
@@ -12,13 +13,6 @@ import asyncio
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def wait_for_first_completed(coros: list[Coroutine]):
|
||||
done, pending = await asyncio.wait([asyncio.create_task(c) for c in coros], return_when = asyncio.FIRST_COMPLETED)
|
||||
for t in pending:
|
||||
t.cancel()
|
||||
for t in done:
|
||||
await t
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@skip_mode('release', 'error injections are not supported in release mode')
|
||||
async def test_coordinator_queue_management(manager: ManagerClient):
|
||||
|
||||
Reference in New Issue
Block a user