import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

# Import directly from modules
from engine import BackgroundEngine

print("Creating engine...")
engine = BackgroundEngine(workers=2)
print("Engine created")

print("Submitting task...")
task = engine.submit(lambda: "test")
print(f"Task submitted: {task}")
print(f"Task state: {task.state}")

print("Waiting for task...")
try:
    result = task.wait(timeout=2)
    print(f"Result: {result}")
except Exception as e:
    print(f"Error: {e}")
    print(f"Task state: {task.state}")
    print(f"Task error: {task.error}")

print("Shutting down engine...")
engine.shutdown()
print("Done")
