Skip to content

Commit

Permalink
feat: disable caching in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loose committed Dec 10, 2024
1 parent 181b18b commit 114916d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ edition = "2021"
# Execute the tests using "cargo test --features db_tests"
db_tests = []

# Used to skip caching of rating data in integration tests
skip_cache = []

[dependencies]
cached = { version = "0.54.0", features = ["async"] }
dotenvy = "0.15"
Expand Down
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ fn init_proto() -> Result<(), Box<dyn std::error::Error>> {
)
.compile(files, &["proto"])?;

if std::env::var("SKIP_CACHE").is_ok() {
println!("cargo:rustc-cfg=feature=\"skip_cache\"");
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
#APP_SNAPCRAFT_IO_URI: "https://api.snapcraft.io/v2/"
APP_ADMIN_USER: "shadow"
APP_ADMIN_PASSWORD: "maria"
SKIP_CACHE: "true"
volumes:
- .:/app
- cargo-cache:/usr/local/cargo/registry
Expand Down
4 changes: 2 additions & 2 deletions src/db/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ impl VoteSummary {
}
}

#[cached(
#[cfg_attr(not(feature = "skip_cache"), cached(
time = 86400, // 24 hours
sync_writes = true,
key = "String",
convert = r##"{String::from(snap_id)}"##,
result = true,
)]
))]
async fn get_by_snap_id_cached(snap_id: &str, conn: &mut PgConnection) -> Result<VoteSummary> {
let result: Option<VoteSummary> = sqlx::query_as(
r#"
Expand Down
4 changes: 2 additions & 2 deletions src/grpc/charts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl chart_server::Chart for ChartService {
}
}

#[cached(
#[cfg_attr(not(feature = "skip_cache"), cached(
time = 86400, // 24 hours
sync_writes = true,
result = true,
with_cached_flag = true
)]
))]
async fn get_cached_chart(
category: Option<Category>,
timeframe: Timeframe,
Expand Down
11 changes: 7 additions & 4 deletions src/ratings/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ async fn get_snap_categories(
}
}

#[cached(
key = "String",
convert = r##"{String::from(snap_id)}"##,
result = true
#[cfg_attr(
not(feature = "skip_cache"),
cached(
key = "String",
convert = r##"{String::from(snap_id)}"##,
result = true
)
)]
async fn get_snap_name(
snap_id: &str,
Expand Down

0 comments on commit 114916d

Please sign in to comment.