2024-10-30 11:40:45 -07:00
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from datahub.utilities.threading_timeout import TimeoutException, threading_timeout
|
|
|
|
|
|
|
|
|
|
|
|
def test_timeout_no_timeout():
|
|
|
|
# Should complete without raising an exception
|
|
|
|
with threading_timeout(1.0):
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
def test_timeout_raises():
|
|
|
|
# Should raise TimeoutException
|
2025-04-23 15:55:46 +02:00
|
|
|
with pytest.raises(TimeoutException), threading_timeout(0.1):
|
|
|
|
time.sleep(0.5)
|
2024-10-30 11:40:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_timeout_early_exit():
|
|
|
|
# Test that context manager handles other exceptions properly
|
2025-04-23 15:55:46 +02:00
|
|
|
with pytest.raises(ValueError), threading_timeout(1.0):
|
|
|
|
raise ValueError("Early exit")
|
2024-10-30 11:40:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
def test_timeout_zero():
|
|
|
|
# Should not raise an exception
|
|
|
|
with threading_timeout(0.0):
|
|
|
|
pass
|