diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c00e62b71..60e1b288a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -96,10 +96,10 @@ jobs: # Tell Launchable about the build you are producing and testing launchable record build --name ${GITHUB_RUN_ID} - launchable record session --build ${GITHUB_RUN_ID} --flavor os=${{ matrix.os }} --flavor python=${{ matrix.python-version }} > session.txt + launchable record session --observation --build ${GITHUB_RUN_ID} --flavor os=${{ matrix.os }} --flavor python=${{ matrix.python-version }} > session.txt # Find 25% of the relevant tests to run for this change - find tests -name test_*.py | grep -v tests/data | launchable subset --target 25% --session $(cat session.txt) --rest launchable-remainder.txt file > subset.txt + find tests -name test_*.py | grep -v tests/data | launchable subset --non-blocking --target 25% --session $(cat session.txt) --rest launchable-remainder.txt file > subset.txt function record() { # Record test results diff --git a/launchable/commands/subset.py b/launchable/commands/subset.py index e25d3b184..2c31b24fe 100644 --- a/launchable/commands/subset.py +++ b/launchable/commands/subset.py @@ -3,6 +3,7 @@ import os import pathlib import sys +from multiprocessing import Process from os.path import join from typing import Any, Callable, Dict, List, Optional, Sequence, TextIO, Tuple, Union @@ -131,10 +132,17 @@ help="outputs the exclude test list. Switch the subset and rest.", is_flag=True, ) +@click.option( + "--non-blocking", + "is_non_blocking", + help="Do not wait for subset requests in observation mode.", + is_flag=True, + hidden=True, +) @click.option( "--ignore-flaky-tests-above", "ignore_flaky_tests_above", - help='Ignore flaky tests above the value set by this option.You can confirm flaky scores in WebApp', + help='Ignore flaky tests above the value set by this option. You can confirm flaky scores in WebApp', type=click.FloatRange(min=0, max=1.0), ) @click.option( @@ -198,6 +206,7 @@ def subset( is_observation: bool, is_get_tests_from_previous_sessions: bool, is_output_exclusion_rules: bool, + is_non_blocking: bool, ignore_flaky_tests_above: Optional[float], links: Sequence[Tuple[str, str]] = (), is_no_build: bool = False, @@ -493,7 +502,15 @@ def run(self): timeout = (5, 300) payload = self.get_payload(session_id, target, duration, test_runner) - res = client.request("post", "subset", timeout=timeout, payload=payload, compress=True) + if is_non_blocking: + # Create a new process for requesting a subset. + process = Process(target=subset_request, args=(client, timeout, payload)) + process.start() + click.echo("The subset was requested in non-blocking mode.", err=True) + self.output_handler(self.test_paths, []) + return + + res = subset_request(client=client, timeout=timeout, payload=payload) # The status code 422 is returned when validation error of the test mapping file occurs. if res.status_code == 422: @@ -600,3 +617,7 @@ def run(self): err=True) context.obj = Optimize(app=context.obj) + + +def subset_request(client: LaunchableClient, timeout: Tuple[int, int], payload: Dict[str, Any]): + return client.request("post", "subset", timeout=timeout, payload=payload, compress=True)