1 //! Ensure we reject connections when SQLite is in single-threaded mode, as it
2 //! would violate safety if multiple Rust threads tried to use connections.
3 
4 use rusqlite::ffi;
5 use rusqlite::Connection;
6 
7 #[test]
test_error_when_singlethread_mode()8 fn test_error_when_singlethread_mode() {
9     // put SQLite into single-threaded mode
10     unsafe {
11         // Note: macOS system SQLite seems to return an error if you attempt to
12         // reconfigure to single-threaded mode.
13         if ffi::sqlite3_config(ffi::SQLITE_CONFIG_SINGLETHREAD) != ffi::SQLITE_OK {
14             return;
15         }
16         assert_eq!(ffi::sqlite3_initialize(), ffi::SQLITE_OK);
17     }
18     let res = Connection::open_in_memory();
19     res.unwrap_err();
20 }
21