fn window_open_close_no_deadlock() {
        use std::ffi::c_void;
        use std::{thread, time};
        use std::fs::File;
        use log::*;
        use rand::prelude::*;

        // Set up a logger so we can see what's going on in the test
        let mut logger_config = simplelog::Config::default();
        logger_config.time_format = Some("%H:%M:%S%.6f");
        simplelog::CombinedLogger::init(vec![simplelog::WriteLogger::new(
            simplelog::LevelFilter::max(),
            logger_config,
            File::create("/tmp/plugin.log").unwrap(),
        )]).unwrap();
        info!("====================================================================");

        let mut rng = rand::thread_rng();

        // Run a bunch of opens/closes as fast as possible
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            window = None;
        }

        // Run a bunch of opens/closes with 1-10 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(1, 11)));
            window = None;
        }

        // Run a bunch of opens/closes with 10-100 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(10, 101)));
            window = None;
        }

        // Run a bunch of opens/closes with 100-1000 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(100, 1001)));
            window = None;
        }
    }
// run with `cargo test window_open_close_no_deadlock -- --ignored`
// Note: this test is obviously annoying: it spawns a bunch of windows over and over again,
// effectively preventing you from doing anything else on your computer while it's running.
// And it takes a while to run.
// TODO: I've noticed a few times where it takes a while to draw the window, is there an issue
// somewhere?
run with `cargo test window_open_close_no_deadlock -- --ignored`
Note: this test is obviously annoying: it spawns a bunch of windows over and over again,
effectively preventing you from doing anything else on your computer while it's running.
And it takes a while to run.
run with ` cargo test window_open_close_no_deadlock -- -- ignored ` Note : this test is obviously annoying : it spawns a bunch of windows over and over again effectively preventing you from doing anything else on your computer while it ' s running . And it takes a while to run .
fn window_open_close_no_deadlock() {
        use std::ffi::c_void;
        use std::{thread, time};
        use std::fs::File;
        use log::*;
        use rand::prelude::*;
        // Set up a logger so we can see what's going on in the test
        let mut logger_config = simplelog::Config::default();
        logger_config.time_format = Some("%H:%M:%S%.6f");
        simplelog::CombinedLogger::init(vec![simplelog::WriteLogger::new(
            simplelog::LevelFilter::max(),
            logger_config,
            File::create("/tmp/plugin.log").unwrap(),
        )]).unwrap();
        info!("====================================================================");
        let mut rng = rand::thread_rng();
        // Run a bunch of opens/closes as fast as possible
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            window = None;
        }
        // Run a bunch of opens/closes with 1-10 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(1, 11)));
            window = None;
        }
        // Run a bunch of opens/closes with 10-100 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(10, 101)));
            window = None;
        }
        // Run a bunch of opens/closes with 100-1000 ms delay
        for i in 0..1000 {
            info!("{}", i);
            let mut window = Some(PlatformWindow::new(0 as *mut c_void));
            thread::sleep(time::Duration::from_millis(rng.gen_range(100, 1001)));
            window = None;
        }
    }
fn window_open_close_no_deadlock ( ) { use std :: ffi :: c_void ; use std :: { thread , time } ; use std :: fs :: File ; use log :: * ; use rand :: prelude :: * ; // Set up a logger so we can see what's going on in the test let mut logger_config = simplelog :: Config :: default ( ) ; logger_config . time_format = Some ( " " ) ; simplelog :: CombinedLogger :: init ( vec ! [ simplelog WriteLogger new ( simplelog LevelFilter max ( ) logger_config File create ( " " ) unwrap ( ) ) ] ) . unwrap ( ) ; info ! ( " " ) ; let mut rng = rand :: thread_rng ( ) ; // Run a bunch of opens/closes as fast as possible for i in 0 .. 1000 { info ! ( " " i ) ; let mut window = Some ( PlatformWindow :: new ( 0 as * mut c_void ) ) ; window = None ; } // Run a bunch of opens/closes with 1-10 ms delay for i in 0 .. 1000 { info ! ( " " i ) ; let mut window = Some ( PlatformWindow :: new ( 0 as * mut c_void ) ) ; thread :: sleep ( time :: Duration :: from_millis ( rng . gen_range ( 1 , 11 ) ) ) ; window = None ; } // Run a bunch of opens/closes with 10-100 ms delay for i in 0 .. 1000 { info ! ( " " i ) ; let mut window = Some ( PlatformWindow :: new ( 0 as * mut c_void ) ) ; thread :: sleep ( time :: Duration :: from_millis ( rng . gen_range ( 10 , 101 ) ) ) ; window = None ; } // Run a bunch of opens/closes with 100-1000 ms delay for i in 0 .. 1000 { info ! ( " " i ) ; let mut window = Some ( PlatformWindow :: new ( 0 as * mut c_void ) ) ; thread :: sleep ( time :: Duration :: from_millis ( rng . gen_range ( 100 , 1001 ) ) ) ; window = None ; } }
run with `cargo test window_open_close_no_deadlock -- --ignored`
Note: this test is obviously annoying: it spawns a bunch of windows over and over again,
effectively preventing you from doing anything else on your computer while it's running.
run with ` cargo test window_open_close_no_deadlock -- -- ignored ` Note : this test is obviously annoying : it spawns a bunch of windows over and over again effectively preventing you from doing anything else on your computer while it ' s running .