From 4ab7aab0ffb0e211962b8395ae332d7440af45c3 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 14 Mar 2024 17:23:53 -0400 Subject: [PATCH] test(index): enable SQLite index cache in CI __CARGO_TEST_FORCE_SQLITE_INDEX_CACHE to force enable it. --- .github/workflows/main.yml | 4 ++++ src/cargo/sources/registry/index/cache.rs | 5 ++++- tests/testsuite/index_cache_sqlite.rs | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f68682cf5a..7634dd99a98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -185,6 +185,10 @@ jobs: - name: Clear test output run: ci/clean-test-output.sh + - name: Check operability of index cache in SQLite3 + run: 'cargo test -p cargo --test testsuite -- alt_registry:: global_cache_tracker::' + env: + __CARGO_TEST_FORCE_SQLITE_INDEX_CACHE: 1 # This only tests `cargo fix` because fix-proxy-mode is one of the most # complicated subprocess management in Cargo. - name: Check operability of rustc invocation with argfile diff --git a/src/cargo/sources/registry/index/cache.rs b/src/cargo/sources/registry/index/cache.rs index 8088f6a7469..84d2640cc50 100644 --- a/src/cargo/sources/registry/index/cache.rs +++ b/src/cargo/sources/registry/index/cache.rs @@ -248,7 +248,10 @@ impl<'gctx> CacheManager<'gctx> { /// /// `root` --- The root path where caches are located. pub fn new(cache_root: Filesystem, gctx: &'gctx GlobalContext) -> CacheManager<'gctx> { - let store: Box = if gctx.cli_unstable().index_cache_sqlite { + #[allow(clippy::disallowed_methods)] + let use_sqlite = gctx.cli_unstable().index_cache_sqlite + || std::env::var("__CARGO_TEST_FORCE_SQLITE_INDEX_CACHE").is_ok(); + let store: Box = if use_sqlite { Box::new(LocalDatabase::new(cache_root, gctx)) } else { Box::new(LocalFileSystem::new(cache_root, gctx)) diff --git a/tests/testsuite/index_cache_sqlite.rs b/tests/testsuite/index_cache_sqlite.rs index a25bab74fd6..f06557aef45 100644 --- a/tests/testsuite/index_cache_sqlite.rs +++ b/tests/testsuite/index_cache_sqlite.rs @@ -46,6 +46,7 @@ fn crates_io() { .with_stderr( "\ [UPDATING] `dummy-registry` index +[LOCKING] 3 packages [DOWNLOADING] crates ... [DOWNLOADED] dep1 v0.0.0 (registry `dummy-registry`) [DOWNLOADED] dep2 v0.0.0 (registry `dummy-registry`) @@ -74,6 +75,8 @@ fn crates_io() { .with_stderr( "\ [UPDATING] `dummy-registry` index +[LOCKING] 1 package +[ADDING] dep3 v0.0.0 [DOWNLOADING] crates ... [DOWNLOADED] dep3 v0.0.0 (registry `dummy-registry`) ",