Skip to content

Commit 29f0d65

Browse files
committed
Add multi-thread test
1 parent 81c4f29 commit 29f0d65

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/test_resample.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
Python-SoXR is a Python wrapper of libsoxr.
1010
"""
1111

12+
from concurrent.futures import ThreadPoolExecutor
13+
from functools import partial
14+
1215
import numpy as np
1316
import pytest
1417
import soxr
@@ -63,7 +66,7 @@ def test_length_match(in_rate, out_rate, length):
6366
assert np.allclose(y_oneshot, y_split)
6467

6568

66-
@pytest.mark.parametrize('channels', [1, 2, 3, 5, 7, 97, 197])
69+
@pytest.mark.parametrize('channels', [1, 2, 3, 5, 7, 24, 49])
6770
def test_channel_match(channels):
6871
x = np.random.randn(30011, channels).astype(np.float32)
6972

@@ -129,7 +132,9 @@ def test_stream_length(in_rate, out_rate, chunk_size, length):
129132
def make_tone(freq, sr, duration):
130133
length = int(sr * duration)
131134
sig = np.sin(2 * np.pi * freq / sr * np.arange(length))
132-
return sig * np.hanning(length)
135+
sig = sig * np.hanning(length)
136+
137+
return np.stack([sig, np.zeros_like(sig)], axis=-1)
133138

134139

135140
@pytest.mark.parametrize('in_rate,out_rate', [(44100, 22050), (22050, 32000)])
@@ -162,3 +167,17 @@ def test_int_sine(in_rate, out_rate, dtype):
162167

163168
assert np.allclose(y, y_pred, atol=2)
164169
assert np.allclose(y, y_split, atol=2)
170+
171+
172+
@pytest.mark.parametrize('num_task', [2, 3, 4, 5, 6, 7, 8, 9, 12, 17, 32])
173+
def test_multithread(num_task):
174+
x = np.random.randn(25999, 2).astype(np.float32)
175+
176+
with ThreadPoolExecutor() as p:
177+
results = p.map(
178+
partial(soxr.resample, in_rate=44100, out_rate=32000),
179+
[x] * num_task
180+
)
181+
results = list(results)
182+
183+
assert np.allclose(results[-2], results[-1])

0 commit comments

Comments
 (0)