Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Windows test fixes. #165

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}