Skip to content

Commit 5e285fd

Browse files
authored
Fix synchronization of datetime tests (#867)
* Fix synchronization of datetime tests * Use Mutex instead of RawMutex
1 parent c2b173a commit 5e285fd

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-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" }
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: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,14 @@ macro_rules! assert_check_only {
5656

5757
// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
5858
// 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-
}
59+
// TODO(kngwyu): Remove this variable
60+
static MUTEX: parking_lot::Mutex<()> = parking_lot::const_mutex(());
6661

6762
#[test]
6863
fn test_date_check() {
64+
let _lock = MUTEX.lock();
6965
let gil = Python::acquire_gil();
7066
let py = gil.python();
71-
lock!();
7267
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "date", "2018, 1, 1").unwrap();
7368

7469
assert_check_exact!(PyDate_Check, obj);
@@ -78,9 +73,9 @@ fn test_date_check() {
7873

7974
#[test]
8075
fn test_time_check() {
76+
let _lock = MUTEX.lock();
8177
let gil = Python::acquire_gil();
8278
let py = gil.python();
83-
lock!();
8479
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "time", "12, 30, 15").unwrap();
8580

8681
assert_check_exact!(PyTime_Check, obj);
@@ -90,9 +85,9 @@ fn test_time_check() {
9085

9186
#[test]
9287
fn test_datetime_check() {
88+
let _lock = MUTEX.lock();
9389
let gil = Python::acquire_gil();
9490
let py = gil.python();
95-
lock!();
9691
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "datetime", "2018, 1, 1, 13, 30, 15")
9792
.map_err(|e| e.print(py))
9893
.unwrap();
@@ -105,9 +100,9 @@ fn test_datetime_check() {
105100

106101
#[test]
107102
fn test_delta_check() {
103+
let _lock = MUTEX.lock();
108104
let gil = Python::acquire_gil();
109105
let py = gil.python();
110-
lock!();
111106
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "timedelta", "1, -3").unwrap();
112107

113108
assert_check_exact!(PyDelta_Check, obj);
@@ -120,9 +115,9 @@ fn test_datetime_utc() {
120115
use assert_approx_eq::assert_approx_eq;
121116
use pyo3::types::PyDateTime;
122117

118+
let _lock = MUTEX.lock();
123119
let gil = Python::acquire_gil();
124120
let py = gil.python();
125-
lock!();
126121
let datetime = py.import("datetime").map_err(|e| e.print(py)).unwrap();
127122
let timezone = datetime.get("timezone").unwrap();
128123
let utc = timezone.getattr("utc").unwrap().to_object(py);

0 commit comments

Comments
 (0)