"""
End-to-end test for idle timeout eviction feature.
Creates a function with idle_timeout=5s, invokes it once to warm up an instance,
then waits for the instance to be evicted by the idle timer.
"""
import logging
import time
import yr
LOGGER = logging.getLogger(__name__)
yr.init()
@yr.invoke(num_cpus=0.1, idle_timeout=5)
def idle_test_func(x):
return x * 2
logging.basicConfig(level=logging.INFO, format="%(levelname)s:%(name)s:%(message)s")
LOGGER.info("[1] Invoking idle_test_func to create an instance...")
ref = idle_test_func.invoke(10)
result = yr.get(ref)
LOGGER.info("[1] Result: %s", result)
assert result == 20, f"Expected 20, got {result}"
LOGGER.info("[2] Waiting 12s for idle timeout eviction (timeout=5s)...")
time.sleep(12)
LOGGER.info("[3] Invoking again - should create a NEW instance after eviction...")
ref2 = idle_test_func.invoke(21)
result2 = yr.get(ref2)
LOGGER.info("[3] Result: %s", result2)
assert result2 == 42, f"Expected 42, got {result2}"
LOGGER.info("\n[OK] idle timeout e2e test passed!")
yr.finalize()