Skip to content

Commit

Permalink
fix: fix coroutine tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Perez committed Nov 20, 2023
1 parent 1e0992a commit af23bce
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tests/test_coroutine.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#![cfg(feature = "macros")]
use futures::channel::oneshot;
use futures::future::poll_fn;
use pyo3::prelude::*;
use pyo3::py_run;
use std::task::Poll;
use std::thread;
use std::time::Duration;
use std::{task::Poll, thread, time::Duration};

use futures::{channel::oneshot, future::poll_fn};
use pyo3::{prelude::*, py_run};

#[path = "../src/tests/common.rs"]
mod common;
Expand Down Expand Up @@ -59,7 +56,12 @@ async fn sleep(seconds: f64) -> usize {
fn sleep_coroutine() {
Python::with_gil(|gil| {
let sleep = wrap_pyfunction!(sleep, gil).unwrap();
let test = "import asyncio; assert asyncio.run(sleep(0.1)) == 42";
let test = r#"
import asyncio, sys
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
assert asyncio.run(sleep(0.1)) == 42
"#;
py_run!(gil, sleep, test);
})
}
Expand All @@ -69,7 +71,9 @@ fn cancelled_coroutine() {
Python::with_gil(|gil| {
let sleep = wrap_pyfunction!(sleep, gil).unwrap();
let test = r#"
import asyncio;
import asyncio, sys
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
async def main():
task = asyncio.create_task(sleep(1))
await asyncio.sleep(0)
Expand Down

0 comments on commit af23bce

Please sign in to comment.