Changeset 7eb4233 in mod_gnutls for test/runtest.py


Ignore:
Timestamp:
Nov 28, 2020, 3:29:24 PM (21 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, master
Children:
65e66c9
Parents:
32e62a3
Message:

Use asyncio to manage test services

This makes it a little easier to handle the services in parallel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/runtest.py

    r32e62a3 r7eb4233  
    1616# limitations under the License.
    1717
     18import asyncio
    1819import contextlib
    1920import os
     
    8586
    8687
    87 def main(args):
     88async def main(args):
    8889    # The Automake environment always provides srcdir, the default is
    8990    # for manual use.
     
    161162            f'http://127.0.0.1:{os.environ["MSVA_PORT"]}'
    162163
    163     with contextlib.ExitStack() as service_stack:
     164    async with contextlib.AsyncExitStack() as service_stack:
    164165        if cleanup_callback:
    165166            service_stack.callback(cleanup_callback)
    166167        service_stack.enter_context(
    167168            lockfile('test.lock', nolock='MGS_NETNS_ACTIVE' in os.environ))
    168         service_stack.enter_context(ocsp.run())
    169         service_stack.enter_context(backend.run())
    170         service_stack.enter_context(msva.run())
    171169
    172170        # TEST_SERVICE_MAX_WAIT is in milliseconds
    173171        wait_timeout = \
    174172            int(os.environ.get('TEST_SERVICE_MAX_WAIT', 10000)) / 1000
    175         for s in bg_services:
    176             if s.condition():
    177                 s.wait_ready(timeout=wait_timeout)
     173        await asyncio.wait(
     174            {asyncio.create_task(
     175                service_stack.enter_async_context(
     176                    s.run(ready_timeout=wait_timeout)))
     177             for s in bg_services})
    178178
    179179        # special case: expected to fail in a few cases
    180         service_stack.enter_context(apache.run())
    181         failed = apache.wait_ready()
     180        await service_stack.enter_async_context(apache.run())
     181        failed = await apache.wait_ready()
    182182        if os.path.exists(os.path.join(testdir, 'fail.server')):
    183183            if failed:
     
    252252        stack.enter_context(contextlib.closing(args.log_connection))
    253253        stack.enter_context(contextlib.closing(args.log_responses))
    254         main(args)
     254        asyncio.run(main(args))
Note: See TracChangeset for help on using the changeset viewer.