From 462b353749e7f6e4bad8f62a4848a4da63e892c3 Mon Sep 17 00:00:00 2001 From: Ezra Singh Date: Tue, 16 Jan 2024 12:12:45 -0500 Subject: [PATCH] Testing CI (#3) * Testing CI * Run tests in a single thread * Removed test wait time * Updated justfile * Updated README --- .github/workflows/release.yml | 2 +- README.md | 14 ++++++++++++++ justfile | 6 +++++- src/backlight.rs | 4 ---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 75fa909..84be621 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,4 +17,4 @@ jobs: run: cargo build - name: Run Unit Tests - run: cargo test + run: cargo test -- --test-threads=1 diff --git a/README.md b/README.md index 8579b52..8822819 100644 --- a/README.md +++ b/README.md @@ -84,3 +84,17 @@ video/brightnessup BRTUP 00000086 00000000 | `brightness_increment` | how much to change brightness on up/down | | `acpi_events.brightness_up` | ACPI event code for brightness up | | `acpi_events.brightness_down` | ACPI event code for brightness down | + +## Unit Testing + +To prevent test from actually modifying system files, I replicated the filesystem needed to run unit test in the `fixtures/` directory. There is also a mock `config.toml` for validating the config parser. + +In order to run the entire test suite you must use a single thread. This is becuase `Rust` will by default run tests in parallel which creates a race-condition for files in the `fixtures/` directory. + +```shell +# use +cargo test -- --test-threads=1 + +# or +just test +``` diff --git a/justfile b/justfile index f265743..2473090 100644 --- a/justfile +++ b/justfile @@ -18,4 +18,8 @@ build: install: build rm -f {{SYMLINK_INSTALL_PATH}} ln -s {{RELEASE_BIN_PATH}} {{SYMLINK_INSTALL_PATH}} - which acpi-keyboard-backlight \ No newline at end of file + which acpi-keyboard-backlight + +# run all unit test in single thread +test: + cargo test -- test-threads=1 \ No newline at end of file diff --git a/src/backlight.rs b/src/backlight.rs index d348ff8..1509e2e 100644 --- a/src/backlight.rs +++ b/src/backlight.rs @@ -83,10 +83,6 @@ mod tests { std::fs::write(helpers.acpi_device_path.join("brightness"), "27182")?; std::fs::write(helpers.acpi_device_path.join("max_brightness"), "31415")?; - // ! required to prevent filesystem race conditions - let wait_time = std::time::Duration::from_secs(1); - std::thread::sleep(wait_time); - Ok(helpers) }