Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename code-examples/roundtrips.py to compare_code_example_output.py #4775

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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/contrib_rerun_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ jobs:
run: |
RUST_LOG=debug tests/roundtrips.py --release --target x86_64-unknown-linux-gnu --no-py-build

- name: Run docs/code-examples/roundtrips.py
- name: Run docs/code-example/compare_code_example_output.py
shell: bash
# --release so we can inherit from some of the artifacts that maturin has just built before
# --target x86_64-unknown-linux-gnu because otherwise cargo loses the target cache… even though this is the target anyhow…
# --no-py-build because rerun-sdk is already built and installed
run: |
RUST_LOG=debug docs/code-examples/roundtrips.py --release --target x86_64-unknown-linux-gnu --no-py-build
RUST_LOG=debug docs/code-example/compare_code_example_output.py --release --target x86_64-unknown-linux-gnu --no-py-build

- name: Cache RRD dataset
id: dataset
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable_test_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ jobs:
run: |
RUST_LOG=debug tests/roundtrips.py --release --target x86_64-unknown-linux-gnu --no-py-build

- name: Run docs/code-examples/roundtrips.py
- name: Run docs/code-example/compare_code_example_output.py
if: ${{ inputs.PLATFORM != 'windows' }}
shell: bash
# --release so we can inherit from some of the artifacts that maturin has just built before
# --target x86_64-unknown-linux-gnu because otherwise cargo loses the target cache… even though this is the target anyhow…
# --no-py-build because rerun-sdk is already built and installed
run: |
RUST_LOG=debug docs/code-examples/roundtrips.py --release --target x86_64-unknown-linux-gnu --no-py-build
RUST_LOG=debug docs/code-example/compare_code_example_output.py --release --target x86_64-unknown-linux-gnu --no-py-build
10 changes: 5 additions & 5 deletions docs/code-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ You can run each example individually using the following:
- **Python**: `python <example_name>.py`, e.g. `python point3d_random.py`.
- **Rust**: `cargo run -p code_examples -- <example_name> [args]`, e.g. `cargo run -p code_examples -- point3d_random`.

## Roundtrips
## Comparison test

All API examples support cross-language roundtrip tests: i.e. we execute the same logging commands from all 3 SDKs, save the results to distinct rrd files, and finally compare these rrd files.
The script `compare_code_example_output.py` execute the same logging commands from all 3 SDKs, save the results to distinct rrd files, and finally compare these rrd files.
These tests are then automatically run by the CI, which will loudly complain if the resulting rrd files don't match.

These tests check that A) all of our SDKs yield the exact same data when used the same way and B) act as regression tests, relying on the fact that it is extremely unlikely that all supported languages break in the exact same way at the exact same time.

### Usage

To run the roundtrip tests, check out `./docs/code-examples/roundtrips.py --help`.
`./docs/code-examples/roundtrips.py` is a valid invocation that will build all 3 SDKs and run all tests for all of them.
To run the comparison tests, check out `./docs/code-examples/compare_code_example_output.py --help`.
`./docs/code-examples/compare_code_example_output.py` is a valid invocation that will build all 3 SDKs and run all tests for all of them.

### Implementing new tests

Just pick a name for your test, and look at existing examples to get started. The `app_id` must be `rerun_example_<test_name>`.

The roundtrip process is driven by file names, so make sure all 3 tests use the same name: `<test_name>.rs`, `<test_name>.cpp`, `<test_name>.py`.
The comparison process is driven by file names, so make sure all 3 tests use the same name: `<test_name>.rs`, `<test_name>.cpp`, `<test_name>.py`.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

"""Run end-to-end cross-language roundtrip tests for all code examples."""
"""Runs all our code-examples, for all our languages, and compares the .rrd they output."""

from __future__ import annotations

Expand All @@ -13,7 +13,7 @@
from os.path import isfile, join

sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../scripts/")
from roundtrip_utils import cmake_build, cmake_configure, cpp_build_dir, roundtrip_env, run, run_comparison # noqa
from roundtrip_utils import roundtrip_env, run, run_comparison # noqa

# fmt: off

Expand Down Expand Up @@ -126,7 +126,6 @@ def main() -> None:
examples.sort()

print("----------------------------------------------------------")
print(f"Running {len(examples)} examples…")

active_languages = ["rust"]
if not args.no_cpp:
Expand All @@ -135,14 +134,15 @@ def main() -> None:
active_languages.append("py")

# Running CMake in parallel causes failures during rerun_sdk & arrow build.
# TODO(andreas): Tell cmake in a single command to build everything at once.
if not args.no_cpp_build:
print(f"Running {len(examples)} C++ examples…")
for example in examples:
example_opt_out_entirely = opt_out_run.get(example, [])
if "cpp" in example_opt_out_entirely:
continue
run_example(example, "cpp", args)

print(f"Running {len(examples)} Rust and Python examples…")
with multiprocessing.Pool() as pool:
jobs = []
for example in examples:
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ def roundtrips(session: nox.Session) -> None:
extra_args.extend(session.posargs)

session.run("python", "tests/roundtrips.py", "--no-py-build", *extra_args)
session.run("python", "docs/code-examples/roundtrips.py", "--no-py-build", *extra_args)
session.run("python", "docs/code-example/compare_code_example_output.py", "--no-py-build", *extra_args)

roundtrip_cpp_built = True
Empty file modified scripts/fast_lint.py
100644 → 100755
Empty file.
4 changes: 1 addition & 3 deletions scripts/roundtrip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def get_repo_root() -> str:
else:
get_rev_parse = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True)
assert get_rev_parse.returncode == 0
repo_root = get_rev_parse.stdout.decode("utf-8").strip()
print("Repository root:", repo_root)
return repo_root
return get_rev_parse.stdout.decode("utf-8").strip()


def run(
Expand Down
Loading