From 87ac5844c5bdb9a657a0f84635c7b4ba06d6b4fe Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 14 Oct 2023 11:13:54 +0200 Subject: [PATCH] macos: Use dispatch to spawn serial tests tasks --- .github/workflows/macos.yml | 11 +++++----- gtk4/Cargo.toml | 3 +++ gtk4/src/lib.rs | 42 +++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 4d3de5cf46c6..77954161a575 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -46,9 +46,8 @@ jobs: with: command: clippy args: --features v4_12,xml_validation --manifest-path ./gtk4/Cargo.toml - # FIXME: renable once https://github.com/gtk-rs/gtk4-rs/issues/1235 is fixed - #- name: Tests - # uses: actions-rs/cargo@v1 - # with: - # command: test - # args: --features v4_8,xml_validation + - name: Tests + uses: actions-rs/cargo@v1 + with: + command: test + args: --features v4_12,xml_validation --manifest-path ./gtk4/Cargo.toml diff --git a/gtk4/Cargo.toml b/gtk4/Cargo.toml index 2a8eea995fa8..6be56bfac92b 100644 --- a/gtk4/Cargo.toml +++ b/gtk4/Cargo.toml @@ -55,5 +55,8 @@ gtk4-macros = {path = "../gtk4-macros", version = "0.8"} libc = "0.2" pango = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["v1_46"]} +[target.'cfg(target_os = "macos")'.dependencies] +dispatch = "0.2.0" + [dev-dependencies] gir-format-check = "^0.1" diff --git a/gtk4/src/lib.rs b/gtk4/src/lib.rs index 19e697a8459f..83d49761ee20 100644 --- a/gtk4/src/lib.rs +++ b/gtk4/src/lib.rs @@ -63,21 +63,37 @@ where { skip_assert_initialized!(); - use std::panic; - use std::sync::mpsc; - - let (tx, rx) = mpsc::sync_channel(1); - TEST_THREAD_WORKER - .push(move || { - tx.send(panic::catch_unwind(function)) - .unwrap_or_else(|_| panic!("Failed to return result from thread pool")); - }) - .expect("Failed to schedule a test call"); - rx.recv() - .expect("Failed to receive result from thread pool") - .unwrap_or_else(|e| std::panic::resume_unwind(e)) + #[cfg(not(target_os = "macos"))] + { + let (tx, rx) = std::sync::mpsc::sync_channel(1); + TEST_THREAD_WORKER + .push(move || { + tx.send(std::panic::catch_unwind(function)) + .unwrap_or_else(|_| panic!("Failed to return result from thread pool")); + }) + .expect("Failed to schedule a test call"); + rx.recv() + .expect("Failed to receive result from thread pool") + .unwrap_or_else(|e| std::panic::resume_unwind(e)) + } + #[cfg(target_os = "macos")] + { + QUEUE + .exec_sync(move || std::panic::catch_unwind(function)) + .unwrap_or_else(|e| std::panic::resume_unwind(e)) + } } +#[cfg(target_os = "macos")] +static QUEUE: glib::once_cell::sync::Lazy = + glib::once_cell::sync::Lazy::new(|| { + let queue = dispatch::Queue::main(); + queue.exec_sync(move || { + crate::init().expect("Failed to initialize GTK"); + }); + queue + }); +#[cfg(not(target_os = "macos"))] static TEST_THREAD_WORKER: glib::once_cell::sync::Lazy = glib::once_cell::sync::Lazy::new(|| { let pool = glib::ThreadPool::exclusive(1).unwrap();