From c78ea76f34aa45a033db5eb3b8eeb15cd4a1b87a Mon Sep 17 00:00:00 2001 From: gintama91 Date: Mon, 10 Jul 2023 22:37:36 +0530 Subject: [PATCH] added temp timeout for tests from rust side --- .rubocop.yml | 3 +- ext/wry_ruby/src/application/window.rs | 58 ++++++++++++++------------ test/test_wry_ruby.rb | 4 +- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e3462a7..c3bfaf6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,7 @@ AllCops: TargetRubyVersion: 2.6 Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes + Enabled: false Style/StringLiteralsInInterpolation: Enabled: true diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index 5f670ef..58ef77e 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -1,19 +1,17 @@ use magnus::{Error, define_global_function, function}; use wry::application::dpi::LogicalSize; use wry::application::window::WindowBuilder; - -use wry::{ - application::{ - event::{Event, StartCause, WindowEvent}, - event_loop::{ControlFlow}, - }, - }; - -pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool) { - let event_loop = wry::application::event_loop::EventLoop::new(); +use wry::application::{ + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, +}; +use std::time::{Duration, Instant}; + +pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout:u64) { + let event_loop = EventLoop::new(); let mut window_builder = WindowBuilder::new(); window_builder = window_builder.with_title(title.clone()); - window_builder = window_builder.with_inner_size(LogicalSize::new(width, height)); + window_builder = window_builder.with_inner_size(LogicalSize::new(width, height)); window_builder = window_builder.with_resizable(resizable); let window = window_builder.build(&event_loop).expect("Failed to create window"); @@ -27,26 +25,34 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool) { println!("Initial Size: {:?}", current_size); println!("Resizable: {}", resizable); - + // ******************************************************* for tests timeout ************************************************************************ + let timeout_duration = Duration::from_secs(timeout); + let start_time = Instant::now(); + event_loop.run(move |event, _, control_flow| { *control_flow = ControlFlow::Wait; - + match event { - Event::NewEvents(StartCause::Init) => println!("Wry has started!"), - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => *control_flow = ControlFlow::Exit, - _ => (), + Event::NewEvents(StartCause::Init) => println!("Wry has started!"), + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + _ => (), } - }); -} + let elapsed = Instant::now() - start_time; + if elapsed >= timeout_duration { + println!("Window creation timed out after {:?}.", timeout_duration); + // Handle the timeout error here + *control_flow = ControlFlow::Exit; + } + }); +} pub fn init() -> Result<(), Error> { -println!("inside init"); - define_global_function("new_window", function!(WindoWnew, 4)); - // define_global_function("hello_wry", function!(new, 3)); - // application::init(); + println!("inside init"); + define_global_function("new_window", function!(WindoWnew, 5)); + Ok(()) -} \ No newline at end of file +} diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index daccf72..51262bb 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class TestWryRuby < Minitest::Test # def test_that_it_has_a_version_number @@ -6,6 +6,6 @@ class TestWryRuby < Minitest::Test # end def test_hello_wry - new_window "Hello Wry",100,400,true # title, width, height, resizable + new_window "Hello Wry", 100, 400, true, 2 # title, width, height, resizable, timeout to close window for tests end end