@@ -2252,39 +2252,36 @@ test_delete_endpoint_full() {
22522252}
22532253
22542254# ###############################################################################
2255- # Main Test Flow
2255+ # Main Test Flow (REFACTORED TO 5 PHASES - OPTIMIZED)
22562256# ###############################################################################
22572257
22582258main () {
22592259 # Capture start time
22602260 local start_time=$( date +%s)
22612261
2262- log_header " RERUM Cache Comprehensive Metrics & Functionality Test"
2262+ log_header " RERUM Cache WORST CASE Metrics Test"
22632263
22642264 echo " This test suite will:"
22652265 echo " 1. Test read endpoints with EMPTY cache (baseline performance)"
2266- echo " 2. Fill cache to 1000 entries"
2267- echo " 3. Test read endpoints with FULL cache (verify speedup)"
2268- echo " 4. Clear cache and test write endpoints with EMPTY cache (baseline)"
2269- echo " Note: Cache cleared to measure pure write performance without invalidation overhead"
2270- echo " 5. Fill cache to 1000 entries again"
2271- echo " 6. Test write endpoints with FULL cache (measure invalidation overhead)"
2272- echo " 7. Generate comprehensive metrics report"
2266+ echo " 2. Test write endpoints with EMPTY cache (baseline performance)"
2267+ echo " 3. Fill cache to 1000 entries (intentionally NON-matching for worst case)"
2268+ echo " 4. Test read endpoints with FULL cache (cache misses - worst case)"
2269+ echo " 5. Test write endpoints with FULL cache (maximum invalidation overhead)"
22732270 echo " "
22742271
22752272 # Setup
22762273 check_server
22772274 get_auth_token
22782275 warmup_system
22792276
2280- # Run all tests following Modified Third Option
2281- log_header " Running Functionality & Performance Tests"
2277+ # Run optimized 5-phase test flow
2278+ log_header " Running Functionality & Performance Tests (Worst Case Scenario) "
22822279
22832280 # ============================================================
22842281 # PHASE 1: Read endpoints on EMPTY cache (baseline)
22852282 # ============================================================
22862283 echo " "
2287- log_section " PHASE 1: Read Endpoints on EMPTY Cache (Baseline)"
2284+ log_section " PHASE 1: Read Endpoints with EMPTY Cache (Baseline)"
22882285 echo " [INFO] Testing read endpoints without cache to establish baseline performance..."
22892286 clear_cache
22902287
@@ -2297,38 +2294,51 @@ main() {
22972294 test_since_endpoint
22982295
22992296 # ============================================================
2300- # PHASE 2: Fill cache with 1000 entries
2297+ # PHASE 2: Write endpoints on EMPTY cache (baseline)
23012298 # ============================================================
23022299 echo " "
2303- log_section " PHASE 2: Fill Cache with 1000 Entries"
2304- echo " [INFO] Filling cache to test read performance at scale..."
2305- fill_cache $CACHE_FILL_SIZE
2300+ log_section " PHASE 2: Write Endpoints with EMPTY Cache (Baseline)"
2301+ echo " [INFO] Testing write endpoints without cache to establish baseline performance..."
2302+
2303+ # Cache is already empty from Phase 1
2304+ test_create_endpoint_empty
2305+ test_update_endpoint_empty
2306+ test_patch_endpoint_empty
2307+ test_set_endpoint_empty
2308+ test_unset_endpoint_empty
2309+ test_overwrite_endpoint_empty
2310+ test_delete_endpoint_empty # Uses objects from create_empty test
23062311
23072312 # ============================================================
2308- # PHASE 3: Read endpoints on FULL cache (WORST CASE - cache misses )
2313+ # PHASE 3: Fill cache with 1000 entries (WORST CASE)
23092314 # ============================================================
23102315 echo " "
2311- log_section " PHASE 3: Read Endpoints on FULL Cache (WORST CASE - Cache Misses )"
2312- echo " [INFO] Testing read endpoints with full cache ( ${CACHE_FILL_SIZE} entries) using queries that DON'T match cache ..."
2313- echo " [INFO] This measures maximum overhead when cache provides NO benefit (full scan, no hits)... "
2316+ log_section " PHASE 3: Fill Cache with 1000 Entries (Worst Case - Non-Matching )"
2317+ echo " [INFO] Filling cache with entries that will NEVER match test queries (worst case) ..."
2318+ fill_cache $CACHE_FILL_SIZE
23142319
2315- # Test read endpoints with queries that will NOT be in the cache (worst case)
2316- # Cache is filled with PerfTest, Annotation, and general queries
2317- # Query for types that don't exist to force full cache scan with no hits
2320+ # ============================================================
2321+ # PHASE 4: Read endpoints on FULL cache (worst case - cache misses)
2322+ # ============================================================
2323+ echo " "
2324+ log_section " PHASE 4: Read Endpoints with FULL Cache (Worst Case - Cache Misses)"
2325+ echo " [INFO] Testing read endpoints with full cache (${CACHE_FILL_SIZE} entries) - all cache misses..."
23182326
2327+ # Test read endpoints WITHOUT clearing cache - but queries intentionally don't match
2328+ # This measures the overhead of scanning the cache without getting hits
23192329 log_info " Testing /api/query with full cache (cache miss - worst case)..."
2320- local result=$( measure_endpoint " ${API_BASE} /api/query" " POST" ' {"type":"NonExistentType999","limit":5 }' " Query with full cache ( miss) " )
2330+ local result=$( measure_endpoint " ${API_BASE} /api/query" " POST" ' {"type":"NonExistentType" }' " Query with cache miss" )
23212331 log_success " Query with full cache (cache miss)"
23222332
23232333 log_info " Testing /api/search with full cache (cache miss - worst case)..."
2324- result=$( measure_endpoint " ${API_BASE} /api/search" " POST" ' {"searchText":"xyzNonExistentQuery999","limit":5 }' " Search with full cache ( miss) " )
2334+ result=$( measure_endpoint " ${API_BASE} /api/search" " POST" ' {"searchText":"zzznomatchzzz" }' " Search with cache miss" )
23252335 log_success " Search with full cache (cache miss)"
23262336
23272337 log_info " Testing /api/search/phrase with full cache (cache miss - worst case)..."
2328- result=$( measure_endpoint " ${API_BASE} /api/search/phrase" " POST" ' {"searchText":"xyzNonExistent phrase999","limit":5 }' " Search phrase with full cache ( miss) " )
2338+ result=$( measure_endpoint " ${API_BASE} /api/search/phrase" " POST" ' {"searchText":"zzz no match zzz" }' " Search phrase with cache miss" )
23292339 log_success " Search phrase with full cache (cache miss)"
23302340
2331- # For ID, history, since - use objects created in Phase 1 (these will cause cache misses too)
2341+ # For ID, history, since - use objects created in Phase 1/2 if available
23322342 if [ ${# CREATED_IDS[@]} -gt 0 ]; then
23332343 local test_id=" ${CREATED_IDS[0]} "
23342344 log_info " Testing /id with full cache (cache miss - worst case)..."
@@ -2353,50 +2363,14 @@ main() {
23532363 fi
23542364
23552365 # ============================================================
2356- # PHASE 4: Clear cache for write baseline
2357- # ============================================================
2358- echo " "
2359- log_section " PHASE 4: Clear Cache for Write Baseline"
2360- echo " [INFO] Clearing cache to establish write performance baseline..."
2361- clear_cache
2362-
2363- # ============================================================
2364- # PHASE 5: Write endpoints on EMPTY cache (baseline)
2366+ # PHASE 5: Write endpoints on FULL cache (worst case - maximum invalidation)
23652367 # ============================================================
23662368 echo " "
2367- log_section " PHASE 5: Write Endpoints on EMPTY Cache (Baseline)"
2368- echo " [INFO] Testing write endpoints without cache to establish baseline performance..."
2369-
2370- # Store number of created objects before empty cache tests
2371- local empty_cache_start_count=${# CREATED_IDS[@]}
2372-
2373- test_create_endpoint_empty
2374- test_update_endpoint_empty
2375- test_patch_endpoint_empty
2376- test_set_endpoint_empty
2377- test_unset_endpoint_empty
2378- test_overwrite_endpoint_empty
2379- test_delete_endpoint_empty # Uses objects from create_empty test
2380-
2381- # ============================================================
2382- # PHASE 6: Fill cache again with 1000 entries
2383- # ============================================================
2384- echo " "
2385- log_section " PHASE 6: Fill Cache Again for Write Comparison"
2386- echo " [INFO] Filling cache with 1000 entries to measure write invalidation overhead..."
2387- fill_cache $CACHE_FILL_SIZE
2388-
2389- # ============================================================
2390- # PHASE 7: Write endpoints on FULL cache (WORST CASE - no invalidations)
2391- # ============================================================
2392- echo " "
2393- log_section " PHASE 7: Write Endpoints on FULL Cache (WORST CASE - No Invalidations)"
2394- echo " [INFO] Testing write endpoints with full cache (${CACHE_FILL_SIZE} entries) using objects that DON'T match cache..."
2395- echo " [INFO] This measures maximum overhead when cache invalidation scans entire cache but finds nothing to invalidate..."
2396-
2397- # Store number of created objects before full cache tests
2398- local full_cache_start_count=${# CREATED_IDS[@]}
2369+ log_section " PHASE 5: Write Endpoints with FULL Cache (Worst Case - Maximum Invalidation Overhead)"
2370+ echo " [INFO] Testing write endpoints with full cache (${CACHE_FILL_SIZE} entries) - all entries must be scanned..."
23992371
2372+ # Cache is already full from Phase 3 - reuse it without refilling
2373+ # This measures worst-case invalidation: scanning all 1000 entries without finding matches
24002374 test_create_endpoint_full
24012375 test_update_endpoint_full
24022376 test_patch_endpoint_full
0 commit comments