This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-rs.git
The following commit(s) were added to refs/heads/master by this push:
new fbbd0c8 fix: stop watcher tests from truncating the shared policy
fixture
fbbd0c8 is described below
commit fbbd0c8cfd3c2772a3e8d78910c1dca34b046d0a
Author: Yang Luo <[email protected]>
AuthorDate: Fri Oct 9 22:32:31 2026 +0800
fix: stop watcher tests from truncating the shared policy fixture
---
src/watcher.rs | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/watcher.rs b/src/watcher.rs
index 344ff98..196f2d8 100644
--- a/src/watcher.rs
+++ b/src/watcher.rs
@@ -11,6 +11,19 @@ mod tests {
use crate::prelude::*;
use std::sync::{Arc, Mutex};
+ // save_policy() rewrites the policy file, so give each test its own copy
+ // instead of truncating the fixture other tests are reading concurrently.
+ #[cfg(not(target_arch = "wasm32"))]
+ fn temp_policy_file(name: &str) -> FileAdapter<std::path::PathBuf> {
+ let path = std::env::temp_dir().join(format!(
+ "casbin_rs_{}_{}.csv",
+ name,
+ std::process::id()
+ ));
+ std::fs::copy("examples/rbac_policy.csv", &path).unwrap();
+ FileAdapter::new(path)
+ }
+
// Sample watcher implementation for testing
struct SampleWatcher {
callback: Option<Box<dyn FnMut(String) + Send + Sync>>,
@@ -49,7 +62,7 @@ mod tests {
async fn test_set_watcher() {
let mut e = Enforcer::new(
"examples/rbac_model.conf",
- "examples/rbac_policy.csv",
+ temp_policy_file("set_watcher"),
)
.await
.unwrap();
@@ -211,7 +224,7 @@ mod tests {
async fn test_set_watcher_ex() {
let mut e = Enforcer::new(
"examples/rbac_model.conf",
- "examples/rbac_policy.csv",
+ temp_policy_file("set_watcher_ex"),
)
.await
.unwrap();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]