#!/usr/bin/env python3 """ Test script to verify timeout handling in PDF processing """ import asyncio import signal from pathlib import Path def test_timeout_mechanism(): """Test the timeout mechanism for PDF processing""" print("⏱️ Testing timeout mechanism for PDF processing...") def timeout_handler(signum, frame): print("✅ Timeout handler works correctly") raise TimeoutError("Operation timed out") # Set up timeout signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(3) # 3 second timeout try: # Simulate a long-running operation print("Starting simulated long operation...") import time time.sleep(5) # This should trigger the timeout print("❌ Operation completed without timeout (unexpected)") except TimeoutError: print("✅ Timeout mechanism working correctly") finally: # Cancel the alarm signal.alarm(0) print("\n🎉 Timeout mechanism test completed") async def test_async_timeout(): """Test async timeout handling""" print("\n⏱️ Testing async timeout handling...") try: # Create a task that should timeout async def long_task(): await asyncio.sleep(5) return "Task completed" # Wait for 3 seconds max result = await asyncio.wait_for(long_task(), timeout=3.0) print(f"❌ Task completed without timeout: {result}") except asyncio.TimeoutError: print("✅ Async timeout working correctly") if __name__ == "__main__": test_timeout_mechanism() asyncio.run(test_async_timeout())