#[test]
fn the_session_resolves_from_a_thread_with_no_tokio_runtime() {
let probe = std::thread::spawn(|| {
let session = vector_core::db::current_session();
let live = vector_core::db::session_is_live();
let chats = vector_core::state::STATE.try_lock().is_ok();
let own = session.chat_state().try_lock().is_ok();
(live, chats, own)
});
let (live, chats, own) = probe.join().expect("resolving the session must not panic off-runtime");
assert!(live, "an unbound caller is, by definition, the account on screen");
assert!(chats, "STATE.try_lock() works with no runtime present");
assert!(own, "and so does locking a held session's state directly");
}
#[test]
fn a_scoped_resource_is_reachable_off_runtime_too() {
struct ProbeKey;
let probe = std::thread::spawn(|| {
let cell = vector_core::db::current_session().scoped::<ProbeKey, std::sync::Mutex<u32>>();
*cell.lock().unwrap() += 1;
let seen = *cell.lock().unwrap();
seen
});
assert_eq!(probe.join().expect("no panic"), 1);
}