Skip to content

Commit

Permalink
Merge pull request #165 from brotskydotcom/windows-threading
Browse files Browse the repository at this point in the history
Release Windows test fixes.
  • Loading branch information
brotskydotcom authored Jan 27, 2024
2 parents de38b48 + 588d18d commit 252f43c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords = ["password", "credential", "keychain", "keyring", "cross-platform"]
license = "MIT OR Apache-2.0"
name = "keyring"
repository = "https://github.com/hwchen/keyring-rs.git"
version = "2.3.1"
version = "2.3.2"
rust-version = "1.68"
edition = "2021"
exclude = [".github/"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ whether through contributing code, discussion, or bug reports!
- @MaikKlein
- @Phrohdoh
- @phlip9
- @ReactorScram
- @Rukenshia
- @russellbanks
- @ryanavella
Expand Down
62 changes: 62 additions & 0 deletions tests/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,65 @@ fn test_simultaneous_independent_create_set() {
handle.join().expect("Couldn't execute on thread")
}
}

#[test]
#[cfg(not(all(feature = "linux-keyutils", not(feature = "secret-service"))))]
fn test_multiple_create_delete_single_thread() {
let name = generate_random_string();
let entry = Entry::new(&name, &name).expect("Can't create entry");
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
let repeats = 10;
#[cfg(any(target_os = "macos", target_os = "windows"))]
let repeats = 10_000;
for _i in 0..repeats {
entry.set_password(&name).expect("Can't set ascii password");
let stored_password = entry.get_password().expect("Can't get ascii password");
assert_eq!(
stored_password, name,
"Retrieved and set ascii passwords don't match"
);
entry
.delete_password()
.expect("Can't delete ascii password");
assert!(
matches!(entry.get_password(), Err(Error::NoEntry)),
"Able to read a deleted ascii password"
);
}
}

#[test]
#[cfg(not(all(feature = "linux-keyutils", not(feature = "secret-service"))))]
fn test_simultaneous_multiple_create_delete_single_thread() {
let mut handles = vec![];
for t in 0..10 {
let root = generate_random_string();
let test = move || {
let name = format!("{root}-{t}");
let entry = Entry::new(&name, &name).expect("Can't create entry");
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
let repeats = 10;
#[cfg(any(target_os = "macos", target_os = "windows"))]
let repeats = 10_000;
for _i in 0..repeats {
entry.set_password(&name).expect("Can't set ascii password");
let stored_password = entry.get_password().expect("Can't get ascii password");
assert_eq!(
stored_password, name,
"Retrieved and set ascii passwords don't match"
);
entry
.delete_password()
.expect("Can't delete ascii password");
assert!(
matches!(entry.get_password(), Err(Error::NoEntry)),
"Able to read a deleted ascii password"
);
}
};
handles.push(std::thread::spawn(test))
}
for handle in handles {
handle.join().expect("Couldn't execute on thread")
}
}

0 comments on commit 252f43c

Please sign in to comment.