|
| 1 | +import os |
1 | 2 | import unittest |
2 | 3 | import time |
3 | 4 | from vfbquery.term_info_queries import deserialize_term_info, deserialize_term_info_from_dict, process |
@@ -582,17 +583,31 @@ def test_term_info_performance(self): |
582 | 583 | self.assertIsNotNone(result_1, "FBbt_00003748 query returned None") |
583 | 584 | self.assertIsNotNone(result_2, "VFB_00101567 query returned None") |
584 | 585 |
|
585 | | - # Performance assertions - fail if queries take too long |
586 | | - # These thresholds are based on observed performance characteristics |
587 | | - max_single_query_time = 10.0 # seconds (increased from 5.0 to account for SOLR cache overhead) |
588 | | - max_total_time = 10.0 # seconds (2 queries * 5 seconds each) |
589 | | - |
590 | | - self.assertLess(duration_1, max_single_query_time, |
591 | | - f"FBbt_00003748 query took {duration_1:.4f}s, exceeding {max_single_query_time}s threshold") |
| 586 | + # Performance assertions - fail if queries take too long. |
| 587 | + # Thresholds depend on whether SOLR result caching is enabled. When |
| 588 | + # VFBQUERY_CACHE_ENABLED=false (CI sets this in python-test.yml so the |
| 589 | + # test exercises the live path), every call is a fresh Neo4j round-trip |
| 590 | + # rather than a cache hit, so timings are roughly an order of magnitude |
| 591 | + # higher. The cache-disabled budget below matches the observed |
| 592 | + # uncached latency on healthy infra (~10-20s per query for FBbt_00003748 |
| 593 | + # which has a large neighbourhood). |
| 594 | + cache_enabled = os.environ.get("VFBQUERY_CACHE_ENABLED", "true").lower() != "false" |
| 595 | + if cache_enabled: |
| 596 | + max_single_query_time = 10.0 |
| 597 | + max_total_time = 10.0 |
| 598 | + else: |
| 599 | + max_single_query_time = 30.0 |
| 600 | + max_total_time = 45.0 |
| 601 | + |
| 602 | + self.assertLess(duration_1, max_single_query_time, |
| 603 | + f"FBbt_00003748 query took {duration_1:.4f}s, exceeding {max_single_query_time}s threshold " |
| 604 | + f"(cache_enabled={cache_enabled})") |
592 | 605 | self.assertLess(duration_2, max_single_query_time, |
593 | | - f"VFB_00101567 query took {duration_2:.4f}s, exceeding {max_single_query_time}s threshold") |
| 606 | + f"VFB_00101567 query took {duration_2:.4f}s, exceeding {max_single_query_time}s threshold " |
| 607 | + f"(cache_enabled={cache_enabled})") |
594 | 608 | self.assertLess(duration_1 + duration_2, max_total_time, |
595 | | - f"Total query time {duration_1 + duration_2:.4f}s exceeds {max_total_time}s threshold") |
| 609 | + f"Total query time {duration_1 + duration_2:.4f}s exceeds {max_total_time}s threshold " |
| 610 | + f"(cache_enabled={cache_enabled})") |
596 | 611 |
|
597 | 612 | # Log success |
598 | 613 | print("Performance test completed successfully!") |
|
0 commit comments