Skip to content

Commit

Permalink
Testing CI (#3)
Browse files Browse the repository at this point in the history
* Testing CI

* Run tests in a single thread

* Removed test wait time

* Updated justfile

* Updated README
  • Loading branch information
ezrasingh authored Jan 16, 2024
1 parent 1322e20 commit 462b353
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
run: cargo build

- name: Run Unit Tests
run: cargo test
run: cargo test -- --test-threads=1
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
6 changes: 5 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ build:
install: build
rm -f {{SYMLINK_INSTALL_PATH}}
ln -s {{RELEASE_BIN_PATH}} {{SYMLINK_INSTALL_PATH}}
which acpi-keyboard-backlight
which acpi-keyboard-backlight

# run all unit test in single thread
test:
cargo test -- test-threads=1
4 changes: 0 additions & 4 deletions src/backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 462b353

Please sign in to comment.