Fix synchronization of datetime tests (#867)

* Fix synchronization of datetime tests

* Use Mutex instead of RawMutex
This commit is contained in:
Yuji Kanagawa 2020-04-11 19:10:16 +09:00 committed by GitHub
parent c2b173a14f
commit 5e285fda78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 13 deletions

View File

@ -25,7 +25,7 @@ libc = "0.2.62"
num-bigint = { version = "0.2", optional = true } num-bigint = { version = "0.2", optional = true }
num-complex = { version = "0.2", optional = true } num-complex = { version = "0.2", optional = true }
num-traits = "0.2.8" num-traits = "0.2.8"
parking_lot = { version = "0.10" } parking_lot = { version = "0.10.2" }
paste = "0.1.6" paste = "0.1.6"
pyo3cls = { path = "pyo3cls", version = "=0.9.2" } pyo3cls = { path = "pyo3cls", version = "=0.9.2" }
unindent = "0.1.4" unindent = "0.1.4"

View File

@ -56,19 +56,14 @@ macro_rules! assert_check_only {
// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756, // Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
// we need to stop other threads before calling `py.import()`. // we need to stop other threads before calling `py.import()`.
// TODO(kngwyu): Remove this macro // TODO(kngwyu): Remove this variable
macro_rules! lock { static MUTEX: parking_lot::Mutex<()> = parking_lot::const_mutex(());
() => {
let _mutex = std::sync::Mutex::new(());
let _lock = _mutex.lock().unwrap();
};
}
#[test] #[test]
fn test_date_check() { fn test_date_check() {
let _lock = MUTEX.lock();
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
lock!();
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "date", "2018, 1, 1").unwrap(); let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "date", "2018, 1, 1").unwrap();
assert_check_exact!(PyDate_Check, obj); assert_check_exact!(PyDate_Check, obj);
@ -78,9 +73,9 @@ fn test_date_check() {
#[test] #[test]
fn test_time_check() { fn test_time_check() {
let _lock = MUTEX.lock();
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
lock!();
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "time", "12, 30, 15").unwrap(); let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "time", "12, 30, 15").unwrap();
assert_check_exact!(PyTime_Check, obj); assert_check_exact!(PyTime_Check, obj);
@ -90,9 +85,9 @@ fn test_time_check() {
#[test] #[test]
fn test_datetime_check() { fn test_datetime_check() {
let _lock = MUTEX.lock();
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
lock!();
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "datetime", "2018, 1, 1, 13, 30, 15") let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "datetime", "2018, 1, 1, 13, 30, 15")
.map_err(|e| e.print(py)) .map_err(|e| e.print(py))
.unwrap(); .unwrap();
@ -105,9 +100,9 @@ fn test_datetime_check() {
#[test] #[test]
fn test_delta_check() { fn test_delta_check() {
let _lock = MUTEX.lock();
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
lock!();
let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "timedelta", "1, -3").unwrap(); let (obj, sub_obj, sub_sub_obj) = _get_subclasses(&py, "timedelta", "1, -3").unwrap();
assert_check_exact!(PyDelta_Check, obj); assert_check_exact!(PyDelta_Check, obj);
@ -120,9 +115,9 @@ fn test_datetime_utc() {
use assert_approx_eq::assert_approx_eq; use assert_approx_eq::assert_approx_eq;
use pyo3::types::PyDateTime; use pyo3::types::PyDateTime;
let _lock = MUTEX.lock();
let gil = Python::acquire_gil(); let gil = Python::acquire_gil();
let py = gil.python(); let py = gil.python();
lock!();
let datetime = py.import("datetime").map_err(|e| e.print(py)).unwrap(); let datetime = py.import("datetime").map_err(|e| e.print(py)).unwrap();
let timezone = datetime.get("timezone").unwrap(); let timezone = datetime.get("timezone").unwrap();
let utc = timezone.getattr("utc").unwrap().to_object(py); let utc = timezone.getattr("utc").unwrap().to_object(py);