Skip to content

Commit

Permalink
Improve CI workflow and test reliability
Browse files Browse the repository at this point in the history
- Add separate test build steps in CI to improve reliability
- Increase tarpaulin timeout and add verbose output
- Optimize CLI tests to use compiled binary directly
- Improve process control test with proper async operations
- Reduce test sleep duration for faster execution
  • Loading branch information
jamesbrink committed Feb 9, 2025
1 parent efc51d9 commit 849637e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Build tests first
run: cargo test --features testing --no-run

- name: Run tests
run: |
if [ -n "${{ matrix.target }}" ] && [ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]; then
Expand Down Expand Up @@ -84,9 +87,12 @@ jobs:
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin

- name: Build tests first
run: cargo test --features testing --no-run

- name: Generate coverage report
run: |
cargo tarpaulin --features testing --out Xml --output-dir coverage --fail-under 80
cargo tarpaulin --features testing --out Xml --output-dir coverage --fail-under 80 --timeout 120 --verbose
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
21 changes: 9 additions & 12 deletions tests/cli_test.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use anyhow::Result;
use std::process::Command;
use std::env;
use std::time::Duration;
use tokio::process::Command as TokioCommand;
use tokio::time::sleep;

// Helper function to run the command to avoid rebuilding for each test
async fn run_strainer_command(args: &[&str]) -> Result<std::process::Output> {
Ok(TokioCommand::new("cargo")
.args(["run", "--"])
.args(args)
.output()
.await?)
// Use the debug build path
let binary_path = env::current_dir()?.join("target/debug/strainer");
Ok(TokioCommand::new(binary_path).args(args).output().await?)
}

#[tokio::test]
Expand Down Expand Up @@ -61,8 +59,7 @@ async fn test_run_command_rate_limits() -> Result<()> {

#[tokio::test]
async fn test_run_command_process_control() -> Result<()> {
let mut child = Command::new("cargo")
.args(["run", "--"])
let mut child = TokioCommand::new(env::current_dir()?.join("target/debug/strainer"))
.args([
"run",
"--api-key",
Expand All @@ -80,12 +77,12 @@ async fn test_run_command_process_control() -> Result<()> {
])
.spawn()?;

// Give it time to start and potentially pause
sleep(Duration::from_millis(500)).await;
// Give it a shorter time to start and potentially pause
sleep(Duration::from_millis(100)).await;

// Kill the process
child.kill()?;
let status = child.wait()?;
child.kill().await?;
let status = child.wait().await?;

// Process should have been killed by us, so it should not exit successfully
assert!(!status.success());
Expand Down

0 comments on commit 849637e

Please sign in to comment.