Skip to content

Commit 43fc660

Browse files
committed
fix: resolve CI failures and reduce test runtime
- Fix redundant closures: replace .map_err(|e| map_manager_err(e)) with .map_err(map_manager_err) in server.rs - Fix non-canonical PartialOrd: delegate partial_cmp to cmp in version.rs - Fix test_init flakiness: make init_db idempotent (already-initialized is not an error) - Add cmake install step to workflow (ubuntu-latest has it pre-installed; step is a safety net) - Remove redundant cargo build steps and --verbose from test script, cutting 4 extra compilations
1 parent 226f260 commit 43fc660

5 files changed

Lines changed: 41 additions & 52 deletions

File tree

.github/workflows/test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- uses: actions/checkout@v6
30+
- name: Install cmake
31+
run: sudo apt-get install -y cmake
3032
- name: Set up Rust
3133
uses: dtolnay/rust-toolchain@stable
3234
with:
@@ -42,6 +44,9 @@ jobs:
4244
- name: Checkout repository
4345
uses: actions/checkout@v6
4446

47+
- name: Install cmake
48+
run: sudo apt-get install -y cmake
49+
4550
- name: Set up Rust
4651
uses: dtolnay/rust-toolchain@stable
4752

src/database/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@ impl Database {
137137
static DB: OnceCell<Database> = OnceCell::new();
138138

139139
/// Initialize the global database. Must be called once before `get_db()`.
140+
/// Idempotent: if already initialized, returns `Ok(())`.
140141
pub fn init_db(data_dir: &Path) -> Result<()> {
142+
if DB.get().is_some() {
143+
return Ok(());
144+
}
141145
let db = Database::open(data_dir)?;
142-
DB.set(db)
143-
.map_err(|_| crate::error::Error::Other("Database already initialized".to_string()))
146+
let _ = DB.set(db); // Ignore error if another thread beat us to it
147+
Ok(())
144148
}
145149

146150
/// Get the global database instance. Panics if `init_db` was not called.

src/manager/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl std::hash::Hash for VersionInfo {
4747

4848
impl PartialOrd for VersionInfo {
4949
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
50-
self.compare(other)
50+
Some(self.cmp(other))
5151
}
5252
}
5353

src/rpc/server.rs

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub async fn run_server(
104104

105105
// Initialize managers (idempotent: only on first call)
106106
if APP_MANAGER.get().is_none() {
107-
let hub_mgr = HubManager::load().map_err(|e| map_manager_err(e))?;
108-
let app_mgr = AppManager::load().map_err(|e| map_manager_err(e))?;
107+
let hub_mgr = HubManager::load().map_err(map_manager_err)?;
108+
let app_mgr = AppManager::load().map_err(map_manager_err)?;
109109
let _ = HUB_MANAGER.set(Arc::new(RwLock::new(hub_mgr)));
110110
let _ = APP_MANAGER.set(Arc::new(RwLock::new(app_mgr)));
111111
}
@@ -465,7 +465,7 @@ pub async fn run_server(
465465
.await
466466
.save_app(request.record)
467467
.await
468-
.map_err(|e| map_manager_err(e))?;
468+
.map_err(map_manager_err)?;
469469
Ok::<crate::database::models::app::AppRecord, ErrorObjectOwned>(saved)
470470
})?;
471471

@@ -478,7 +478,7 @@ pub async fn run_server(
478478
.await
479479
.remove_app(&request.record_id)
480480
.await
481-
.map_err(|e| map_manager_err(e))?;
481+
.map_err(map_manager_err)?;
482482
Ok::<bool, ErrorObjectOwned>(deleted)
483483
})?;
484484

@@ -526,7 +526,7 @@ pub async fn run_server(
526526
.await
527527
.upsert_hub(request.record)
528528
.await
529-
.map_err(|e| map_manager_err(e))?;
529+
.map_err(map_manager_err)?;
530530
Ok::<bool, ErrorObjectOwned>(true)
531531
})?;
532532

@@ -539,7 +539,7 @@ pub async fn run_server(
539539
.await
540540
.remove_hub(&request.hub_uuid)
541541
.await
542-
.map_err(|e| map_manager_err(e))?;
542+
.map_err(map_manager_err)?;
543543
Ok::<bool, ErrorObjectOwned>(deleted)
544544
})?;
545545

@@ -563,10 +563,7 @@ pub async fn run_server(
563563
hub.user_ignore_app_id_list
564564
.retain(|id| id != &request.app_id);
565565
}
566-
guard
567-
.upsert_hub(hub)
568-
.await
569-
.map_err(|e| map_manager_err(e))?;
566+
guard.upsert_hub(hub).await.map_err(map_manager_err)?;
570567
Ok::<bool, ErrorObjectOwned>(true)
571568
})?;
572569

@@ -583,10 +580,7 @@ pub async fn run_server(
583580
)
584581
})?;
585582
hub.applications_mode = if request.enable { 1 } else { 0 };
586-
guard
587-
.upsert_hub(hub)
588-
.await
589-
.map_err(|e| map_manager_err(e))?;
583+
guard.upsert_hub(hub).await.map_err(map_manager_err)?;
590584
Ok::<bool, ErrorObjectOwned>(true)
591585
})?;
592586

@@ -598,7 +592,7 @@ pub async fn run_server(
598592
module.register_async_method("manager_get_extra_hubs", |_, _, _| async move {
599593
let extra_hubs = crate::database::get_db()
600594
.load_extra_hubs()
601-
.map_err(|e| map_manager_err(e))?;
595+
.map_err(map_manager_err)?;
602596
Ok::<Vec<crate::database::models::extra_hub::ExtraHubRecord>, ErrorObjectOwned>(extra_hubs)
603597
})?;
604598

@@ -607,7 +601,7 @@ pub async fn run_server(
607601
let request = params.parse::<RpcSaveExtraHubRequest>()?;
608602
crate::database::get_db()
609603
.upsert_extra_hub(&request.record)
610-
.map_err(|e| map_manager_err(e))?;
604+
.map_err(map_manager_err)?;
611605
Ok::<bool, ErrorObjectOwned>(true)
612606
})?;
613607

@@ -616,7 +610,7 @@ pub async fn run_server(
616610
let request = params.parse::<RpcGetExtraHubRequest>()?;
617611
let deleted = crate::database::get_db()
618612
.delete_extra_hub(&request.id)
619-
.map_err(|e| map_manager_err(e))?;
613+
.map_err(map_manager_err)?;
620614
Ok::<bool, ErrorObjectOwned>(deleted)
621615
})?;
622616

@@ -649,7 +643,7 @@ pub async fn run_server(
649643
let request = params.parse::<RpcGetExtraAppRequest>()?;
650644
let record = crate::database::get_db()
651645
.get_extra_app_by_app_id(&request.app_id)
652-
.map_err(|e| map_manager_err(e))?;
646+
.map_err(map_manager_err)?;
653647
Ok::<Option<crate::database::models::extra_app::ExtraAppRecord>, ErrorObjectOwned>(
654648
record,
655649
)
@@ -661,7 +655,7 @@ pub async fn run_server(
661655
let request = params.parse::<RpcSaveExtraAppRequest>()?;
662656
crate::database::get_db()
663657
.upsert_extra_app(&request.record)
664-
.map_err(|e| map_manager_err(e))?;
658+
.map_err(map_manager_err)?;
665659
Ok::<bool, ErrorObjectOwned>(true)
666660
})?;
667661

@@ -670,7 +664,7 @@ pub async fn run_server(
670664
let request = params.parse::<RpcDeleteExtraAppRequest>()?;
671665
let deleted = crate::database::get_db()
672666
.delete_extra_app(&request.id)
673-
.map_err(|e| map_manager_err(e))?;
667+
.map_err(map_manager_err)?;
674668
Ok::<bool, ErrorObjectOwned>(deleted)
675669
})?;
676670

@@ -695,12 +689,7 @@ pub async fn run_server(
695689
None::<String>,
696690
)
697691
})?;
698-
getter
699-
.read()
700-
.await
701-
.renew()
702-
.await
703-
.map_err(|e| map_manager_err(e))?;
692+
getter.read().await.renew().await.map_err(map_manager_err)?;
704693
Ok::<bool, ErrorObjectOwned>(true)
705694
})?;
706695

@@ -751,7 +740,7 @@ pub async fn run_server(
751740
&mut *hub_mgr.write().await,
752741
)
753742
.await
754-
.map_err(|e| map_manager_err(e))?;
743+
.map_err(map_manager_err)?;
755744
Ok::<bool, ErrorObjectOwned>(true)
756745
})?;
757746

@@ -771,7 +760,7 @@ pub async fn run_server(
771760
.await
772761
.apply_hub_config(&request.uuid, &mut *hub_mgr.write().await)
773762
.await
774-
.map_err(|e| map_manager_err(e))?;
763+
.map_err(map_manager_err)?;
775764
Ok::<bool, ErrorObjectOwned>(true)
776765
})?;
777766

@@ -791,7 +780,7 @@ pub async fn run_server(
791780
.await
792781
.renew_all_from_cloud(&mut *app_mgr.write().await, &mut *hub_mgr.write().await)
793782
.await
794-
.map_err(|e| map_manager_err(e))?;
783+
.map_err(map_manager_err)?;
795784
Ok::<bool, ErrorObjectOwned>(true)
796785
})?;
797786

tests/script/cargo_test.sh

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,23 @@
33
# function for running a command and printing it
44
# if command failed, print notification and exit
55
function run {
6-
echo "Running: $@"
7-
"$@"
8-
local status=$?
9-
if [ $status -ne 0 ]; then
10-
echo "Command failed: $@"
11-
exit $status
12-
fi
6+
echo "Running: $@"
7+
"$@"
8+
local status=$?
9+
if [ $status -ne 0 ]; then
10+
echo "Command failed: $@"
11+
exit $status
12+
fi
1313
}
1414

15-
echo "Building with default features"
16-
run cargo build --verbose
1715
echo "Testing with default features"
18-
run cargo test --verbose
16+
run cargo test
1917

20-
echo "Building with each feature individually"
21-
for feature in "rustls-platform-verifier" "webpki-roots" "native-tokio"; do
22-
echo "Building with feature: $feature"
23-
run cargo build --verbose --no-default-features --features "$feature"
24-
done
2518
echo "Testing with each feature individually"
2619
for feature in "rustls-platform-verifier" "webpki-roots" "native-tokio"; do
27-
echo "Testing with feature: $feature"
28-
run cargo test --verbose --no-default-features --features "$feature"
20+
echo "Testing with feature: $feature"
21+
run cargo test --no-default-features --features "$feature"
2922
done
3023

31-
echo "Building with all features"
32-
run cargo build --verbose --all-features
3324
echo "Testing with all features"
34-
run cargo test --verbose --all-features
25+
run cargo test --all-features

0 commit comments

Comments
 (0)