Skip to content

Commit e70ed61

Browse files
committed
Fix synchronization of datetime tests
1 parent 7b1e8a6 commit e70ed61

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ libc = "0.2.62"
2525
num-bigint = { version = "0.2", optional = true }
2626
num-complex = { version = "0.2", optional = true }
2727
num-traits = "0.2.8"
28-
parking_lot = { version = "0.10", features = ["nightly"] }
28+
parking_lot = { version = "0.10.2" }
2929
paste = "0.1.6"
3030
pyo3cls = { path = "pyo3cls", version = "=0.9.2" }
3131
unindent = "0.1.4"

tests/test_datetime.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(concat_idents)]
22

3+
use parking_lot::{lock_api::RawMutex as _RawMutex, RawMutex};
34
use pyo3::ffi::*;
45
use pyo3::prelude::*;
56
use pyo3::types::IntoPyDict;
@@ -56,19 +57,14 @@ macro_rules! assert_check_only {
5657

5758
// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
5859
// we need to stop other threads before calling `py.import()`.
59-
// TODO(kngwyu): Remove this macro
60-
macro_rules! lock {
61-
() => {
62-
let _mutex = std::sync::Mutex::new(());
63-
let _lock = _mutex.lock().unwrap();
64-
};
65-
}
60+
// TODO(kngwyu): Remove this variable
61+
const MUTEX: RawMutex = RawMutex::INIT;
6662

6763
#[test]
6864
fn test_date_check() {
65+
let _lock = MUTEX.lock();
6966
let gil = Python::acquire_gil();
7067
let py = gil.python();
71-
lock!();
7268
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "date", "2018, 1, 1").unwrap();
7369

7470
assert_check_exact!(PyDate_Check, obj);
@@ -78,9 +74,9 @@ fn test_date_check() {
7874

7975
#[test]
8076
fn test_time_check() {
77+
let _lock = MUTEX.lock();
8178
let gil = Python::acquire_gil();
8279
let py = gil.python();
83-
lock!();
8480
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "time", "12, 30, 15").unwrap();
8581

8682
assert_check_exact!(PyTime_Check, obj);
@@ -90,9 +86,9 @@ fn test_time_check() {
9086

9187
#[test]
9288
fn test_datetime_check() {
89+
let _lock = MUTEX.lock();
9390
let gil = Python::acquire_gil();
9491
let py = gil.python();
95-
lock!();
9692
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "datetime", "2018, 1, 1, 13, 30, 15")
9793
.map_err(|e| e.print(py))
9894
.unwrap();
@@ -105,9 +101,9 @@ fn test_datetime_check() {
105101

106102
#[test]
107103
fn test_delta_check() {
104+
let _lock = MUTEX.lock();
108105
let gil = Python::acquire_gil();
109106
let py = gil.python();
110-
lock!();
111107
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "timedelta", "1, -3").unwrap();
112108

113109
assert_check_exact!(PyDelta_Check, obj);
@@ -120,9 +116,9 @@ fn test_datetime_utc() {
120116
use assert_approx_eq::assert_approx_eq;
121117
use pyo3::types::PyDateTime;
122118

119+
let _lock = MUTEX.lock();
123120
let gil = Python::acquire_gil();
124121
let py = gil.python();
125-
lock!();
126122
let datetime = py.import("datetime").map_err(|e| e.print(py)).unwrap();
127123
let timezone = datetime.get("timezone").unwrap();
128124
let utc = timezone.getattr("utc").unwrap().to_object(py);

0 commit comments

Comments
 (0)