Skip to content

Commit

Permalink
added temp timeout for tests from rust side
Browse files Browse the repository at this point in the history
  • Loading branch information
gintama91 committed Jul 10, 2023
1 parent b26a69a commit c78ea76
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ AllCops:
TargetRubyVersion: 2.6

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: true
Expand Down
58 changes: 32 additions & 26 deletions ext/wry_ruby/src/application/window.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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(())
}
}
4 changes: 2 additions & 2 deletions test/test_wry_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'test_helper'
require "test_helper"

class TestWryRuby < Minitest::Test
# def test_that_it_has_a_version_number
# refute_nil ::WryRuby::VERSION
# 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

0 comments on commit c78ea76

Please sign in to comment.