Skip to content

Commit

Permalink
Merge pull request #17 from jymchng/feature/#16_test_scoped_concurrency
Browse files Browse the repository at this point in the history
Feature/#16 test scoped concurrency
  • Loading branch information
jymchng authored Nov 27, 2023
2 parents ad3d07a + 5db7a9f commit e3a1fa4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions tests/extern_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,45 @@ fn test_with_new_alloc() {
SecretString(env::var("CARGO_TARGET_DIR").unwrap_or("MySecret".to_string()))
);
}

#[test]
fn test_scoped_concurrency() {
use std::thread::scope;

let new_secret = Secret::<i32, U2>::new_with(|| 69);
let new_secret_two = Secret::<String, U2>::new_with(|| "69".to_owned());

scope(|s| {
s.spawn(move || {
let (new_secret, returned_value) =
new_secret.expose_secret(|exposed_secret| *exposed_secret);
assert_eq!(69, returned_value);
let (_new_secret, returned_value) =
new_secret.expose_secret(|exposed_secret| *exposed_secret);
assert_eq!(69, returned_value);
});
s.spawn(move || {
let (new_secret_two, returned_value) =
new_secret_two.expose_secret(|exposed_secret| exposed_secret.to_owned());
assert_eq!("69".to_owned(), returned_value);
let (_new_secret_two, returned_value) =
new_secret_two.expose_secret(|exposed_secret| exposed_secret.to_owned());
assert_eq!("69".to_owned(), returned_value);
});
});
}

#[test]
fn test_scoped_concurrency_the_other_way_round() {
use std::thread::scope;

let new_secret = Secret::<i32, U2>::new_with(|| 69);

let (_new_secret, _) = new_secret.expose_secret(|exposed_secret| {
scope(|s| {
let scope_handler = s.spawn(move || exposed_secret.clone());
let result = scope_handler.join();
assert_eq!(result.unwrap(), 69);
});
});
}
4 changes: 2 additions & 2 deletions trybuild_tests/test_compile_fail_six.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0271]: type mismatch resolving `<UInt<UInt<UTerm, B1>, B1> as IsLessOrEqual<UInt<UInt<UTerm, B1>, B0>>>::Output == B1`
--> trybuild_tests/test_compile_fail_six.rs:27:58
--> trybuild_tests/test_compile_fail_six.rs:26:58
|
27 | let (_cloned_secret, returned_value) = cloned_secret.expose_secret(|exposed_secret| {
26 | let (_cloned_secret, returned_value) = cloned_secret.expose_secret(|exposed_secret| {
| ^^^^^^^^^^^^^ expected `B1`, found `B0`
|
note: required by a bound in `sosecrets_rs::traits::ExposeSecret::Next`
Expand Down

0 comments on commit e3a1fa4

Please sign in to comment.