test_heartbeat_config.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """
  3. Test script to demonstrate configurable heartbeat interval
  4. """
  5. import os
  6. import sys
  7. from pathlib import Path
  8. # Add the src directory to the path
  9. project_root = Path(__file__).parent
  10. sys.path.insert(0, str(project_root / 'src'))
  11. def test_heartbeat_config():
  12. """Test the configurable heartbeat interval."""
  13. print("🧪 Testing Configurable Bot Heartbeat")
  14. print("=" * 50)
  15. # Test with different values
  16. test_values = [
  17. ("10", "Fast monitoring (10 seconds)"),
  18. ("30", "Default monitoring (30 seconds)"),
  19. ("60", "Slow monitoring (60 seconds)"),
  20. ("300", "Very slow monitoring (5 minutes)"),
  21. ("3", "Too fast (should warn)"),
  22. ("700", "Too slow (should warn)")
  23. ]
  24. for value, description in test_values:
  25. print(f"\n🔍 Testing: {description}")
  26. # Set environment variable
  27. os.environ['BOT_HEARTBEAT_SECONDS'] = value
  28. # Reload config (simulate fresh import)
  29. if 'config' in sys.modules:
  30. del sys.modules['config']
  31. try:
  32. from config import Config
  33. print(f" 📊 BOT_HEARTBEAT_SECONDS: {Config.BOT_HEARTBEAT_SECONDS}")
  34. # Test validation
  35. is_valid = Config.validate()
  36. print(f" ✅ Validation: {'PASSED' if is_valid else 'FAILED'}")
  37. # Show what the monitoring message would say
  38. print(f" 📱 Monitoring message: 'Order monitoring: Active ({Config.BOT_HEARTBEAT_SECONDS}s interval)'")
  39. except Exception as e:
  40. print(f" ❌ Error: {e}")
  41. print(f"\n🎉 Heartbeat configuration test complete!")
  42. print(f"💡 Set BOT_HEARTBEAT_SECONDS in your .env file to customize the monitoring interval")
  43. if __name__ == "__main__":
  44. test_heartbeat_config()