Skip to content

Commit

Permalink
tests: run binaries sequentially instead
Browse files Browse the repository at this point in the history
Tests are bounded by IO, so running tests asynchronously doesn't add
value, instead add more complexity only.

Signed-off-by: Thing-han, Lim <[email protected]>
  • Loading branch information
potsrevennil committed Nov 6, 2024
1 parent 76a55ce commit 3623250
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import logging
import click
import hashlib
import yaml
import asyncio
from functools import reduce
from enum import IntEnum
from typing import Optional, Callable, TypedDict
Expand Down Expand Up @@ -259,7 +258,7 @@ class State(object):
exec_wrapper = exec_wrapper.split(" ")
cmd = exec_wrapper + cmd

logging.info(" ".join(cmd))
logging.debug(" ".join(cmd))
result = subprocess.run(
cmd,
capture_output=True,
Expand Down Expand Up @@ -755,54 +754,47 @@ def all(

return code

async def run(f, _state: State, opt: bool):
def run(f, _state: State, opt: bool):
code = 0
opt_label = "opt" if opt else "no-opt"
if gh_env is not None:
print(
f"::group::run {compile_mode} {opt_label} {f.__name__.removeprefix('_')} test"
)

with redirect_stdout(io.StringIO()) as out:
try:
f(_state, opt)
except SystemExit as e:
code = e

if out:
print(out.getvalue())
try:
f(_state, opt)
except SystemExit as e:
code = e

if gh_env is not None:
print(f"::endgroup::")
sys.stdout.flush()

return code

async def run_all(_state: State, opt: str):
ts = []
async with asyncio.TaskGroup() as g:
for f in tests:
if opt.lower() == "all" or opt.lower() == "no_opt":
ts.append(g.create_task(run(f, _state, False)))
if opt.lower() == "all" or opt.lower() == "opt":
ts.append(g.create_task(run(f, _state, True)))
return reduce(lambda acc, c: acc or c, map(lambda t: t.result(), ts), exit_code)
def run_all(_state: State, opt: str):
code = 0
for f in tests:
if opt.lower() == "all" or opt.lower() == "no_opt":
code = code or run(f, _state, False)
if opt.lower() == "all" or opt.lower() == "opt":
code = code or run(f, _state, True)
return code

exit_code = 0

# sequentially compile
if state.compile:
_state = copy.deepcopy(state)
_state.run = False

exit_code = compile_all(_state, opt)

# parallelly run
if state.run:
_state = state
_state.compile = False

exit_code = asyncio.run(run_all(_state, opt))
exit_code = exit_code or run_all(_state, opt)

exit(exit_code)

Expand Down

0 comments on commit 3623250

Please sign in to comment.