Skip to content

Commit 8cf5e09

Browse files
committed
Test with Python threads
1 parent 922ec9b commit 8cf5e09

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

light-curve/tests/light_curve_ext/test_feature.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import inspect
33
import pickle
4+
from concurrent.futures import ThreadPoolExecutor
45

56
import numpy as np
67
import pytest
@@ -174,7 +175,24 @@ def test_many_vs_call(feature):
174175

175176
call = np.stack([feature(*lc, sorted=True) for lc in lcs])
176177
many = feature.many(lcs, sorted=True, n_jobs=2)
177-
assert_array_equal(many, call)
178+
assert_array_equal(call, many)
179+
180+
# Test with Python threads to ensure we have no problems on the free-threading CPython
181+
with ThreadPoolExecutor(2) as pool:
182+
futures = [pool.submit(feature, *lc, sorted=True) for lc in lcs]
183+
call_threads = np.stack([f.result() for f in futures])
184+
del futures
185+
assert_array_equal(call, call_threads)
186+
187+
n_lcs_per_job = 4
188+
with ThreadPoolExecutor(2) as pool:
189+
futures = [
190+
pool.submit(feature.many, lcs[i : i + n_lcs_per_job], sorted=True, n_jobs=2)
191+
for i in range(0, n_lc, n_lcs_per_job)
192+
]
193+
many_threads = np.concatenate([f.result() for f in futures])
194+
del futures
195+
assert_array_equal(call, many_threads)
178196

179197

180198
def test_fill_value_not_enough_observations():

0 commit comments

Comments
 (0)