Skip to content
Closed

test #970

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 51 additions & 2 deletions launchable/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -291,6 +300,34 @@ def subset(
else:
click.echo(ignorable_error(e), err=True)

if is_non_blocking:
if (not is_observation) and session_id:
try:
client = LaunchableClient(
app=app,
tracking_client=tracking_client)
res = client.request("get", session_id)
is_observation_in_recorded_session = res.json().get("isObservation", False)
if not is_observation_in_recorded_session:
msg = "You have to specify --observation option to use non-blocking mode"
click.echo(
click.style(
msg,
fg="red"),
err=True,
)
tracking_client.send_error_event(
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
stack_trace=msg,
)
sys.exit(1)
except Exception as e:
tracking_client.send_error_event(
event_name=Tracking.ErrorEvent.INTERNAL_CLI_ERROR,
stack_trace=str(e),
)
click.echo(ignorable_error(e), err=True)

file_path_normalizer = FilePathNormalizer(base_path, no_base_path_inference=no_base_path_inference)

# TODO: placed here to minimize invasion in this PR to reduce the likelihood of
Expand Down Expand Up @@ -493,7 +530,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:
Expand Down Expand Up @@ -600,3 +645,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)