Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuthaDev committed Dec 30, 2024
1 parent 336eceb commit e74b921
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 206 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/cypress-tests-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ env:
RUN_TESTS: ${{ ((github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name)) || (github.event_name == 'merge_group')}}
DEBUG: cypress:cli
RUST_MIN_STACK: 10485760
CODECOV_FILE: "lcov.info"

jobs:
formatter:
Expand Down Expand Up @@ -259,6 +258,8 @@ jobs:
runner_v2:
name: Run Cypress tests on v2 and generate coverage report
runs-on: ubuntu-latest
env:
CODECOV_FILE: "lcov.info"

services:
redis:
Expand Down Expand Up @@ -336,7 +337,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable 2 weeks ago
components: clippy llvm-tools-preview
components: llvm-tools-preview

- name: Install sccache
if: ${{ env.RUN_TESTS == 'true' }}
Expand All @@ -355,9 +356,10 @@ jobs:

- name: Install grcov
if: ${{ env.RUN_TESTS == 'true' }}
uses: baptiste0928/cargo-install@v3.1.1
uses: taiki-e/install-action@v2.41.10
with:
crate: grcov
tool: grcov
checksum: true

- name: Install Just
if: ${{ env.RUN_TESTS == 'true' }}
Expand Down Expand Up @@ -428,7 +430,7 @@ jobs:
shell: bash -leuo pipefail {0}
continue-on-error: true
run: |
scripts/execute_cypress_v2.sh
scripts/execute_cypress_v2.sh "" "" "cypress-tests-v2"
- name: Stop running server
if: ${{ env.RUN_TESTS == 'true' }} && always()
Expand Down
23 changes: 17 additions & 6 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,42 +225,51 @@ cargo +nightly fmt

### Code Coverage

We value well tested code. You should try to add tests for the code you add.
We appreciate well-tested code, so feel free to add tests when you can.

For generating code coverage, follow the following steps:
To generate code coverage using the cypress tests, follow these steps:

- Make sure `grcov` and `llvm-tools-preview` are installed

```shell
rustup install llvm-tools-preview
cargo install grcov
```

- Build the project with the `-Cinstrument-coverage` flag:

```shell
RUSTFLAGS="-Cinstrument-coverage" cargo build --bin=router --package=router
```

Several `.profraw` files will be generated.
Several `.profraw` files will be generated. (Due to the execution of build scripts)

- Execute the binary:

- Run the project using:
```shell
LLVM_PROFILE_FILE="coverage.profraw" target/debug/router
```

- Open a separate terminal tab and run the cypress tests, following the README
- Open a separate terminal tab and run the cypress tests, following the [README]

- After the tests have finished running, stop the `router` process using `Ctrl+C`

- The generated `coverage.profraw` file will contain the code coverage data for `router`

- Generate an html report from the data using:
- Generate an html report from the data:

```shell
grcov . --source-dir . --output-type html --binary-path ./target/debug
```

- A folder named `html` will be generated, containing the report. You can view it using:

```shell
cd html && python3 -m http.server 8000
```

- You can delete the generated `.profraw` files using:

```shell
rm **/*.profraw
```
Expand All @@ -269,6 +278,8 @@ Note:
- It is necessary to stop the `router` process to generate the coverage file
- Branch coverage generation requires nightly and currently `grcov` crashes while trying to include branch coverage. (Checked using `--log-level` parameter in `grcov`)

[README]: /cypress-tests-v2/README.md

### Commits

It is a recommended best practice to keep your changes as logically grouped as
Expand Down
2 changes: 0 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ build_v2 *FLAGS:
cargo build --package router --bin router --no-default-features --features "${FEATURES}" {{ FLAGS }}
set +x

alias bb := build_v2


run_v2:
#! /usr/bin/env bash
Expand Down
11 changes: 6 additions & 5 deletions scripts/execute_cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ function cleanup() {
function main() {
local command="${1:-}"
local jobs="${2:-5}"
local test_dir="${3:-cypress-tests}"

# Ensure script runs from 'cypress-tests' directory
if [[ "$(basename "$PWD")" != "cypress-tests" ]]; then
print_color "yellow" "Changing directory to 'cypress-tests'..."
cd cypress-tests || {
print_color "red" "ERROR: Directory 'cypress-tests' not found!"
# Ensure script runs from the specified test directory (default: cypress-tests)
if [[ "$(basename "$PWD")" != "$(basename "$test_dir")" ]]; then
print_color "yellow" "Changing directory to '${test_dir}'..."
cd "${test_dir}" || {
print_color "red" "ERROR: Directory '${test_dir}' not found!"
exit 1
}
fi
Expand Down
188 changes: 0 additions & 188 deletions scripts/execute_cypress_v2.sh

This file was deleted.

0 comments on commit e74b921

Please sign in to comment.