Fix TAP test when statement count after worker threads is below cache

limit. Calculate dynamically how many statements to create to ensure we
exceed CACHE_LIMIT (1024) and trigger a purge.
pull/5353/head
Rahim Kanji 3 months ago
parent 8ca6323eef
commit d42d89ae36

@ -333,22 +333,11 @@ bool test_concurrent_prepared_statements() {
PQclear(res);
// Verification 1: Analyze the results to determine if purges occurred
// Verify purge mechanism by creating enough statements to exceed cache limit
// This forces a purge to trigger, verifying purge logic works correctly
diag("=== Purge Verification: Active Cache Limit Enforcement ===");
bool purge_verified = false;
diag("=== Purge Verification - Part 1 ===");
diag(" Cache limit (pgsql-max_stmts_cache): %d", CACHE_LIMIT);
diag(" Actual statement count: %d", stmt_count);
if (stmt_count <= CACHE_LIMIT) {
// Purge is working correctly - count is at or below cache limit
diag("PASS: Cache limit ENFORCED - count (%d) <= limit (%d)", stmt_count, CACHE_LIMIT);
purge_verified = true;
}
// Verification 2: Verify that the purge mechanism itself works by creating new statements
// and seeing that old ones are purged when cache limit is exceeded
diag("=== Purge Verification - Part 2: Active Cache Limit Enforcement ===");
int stmt_count_before = 0;
res = PQexec(admin_conn.get(), "SELECT COUNT(*) FROM stats_pgsql_prepared_statements_info");
if (PQresultStatus(res) == PGRES_TUPLES_OK) {
@ -356,14 +345,23 @@ bool test_concurrent_prepared_statements() {
}
PQclear(res);
// Create 100 unique statements with different queries
// This forces the cache to exceed the limit, triggering a purge
diag("Cache limit (pgsql-max_stmts_cache): %d", CACHE_LIMIT);
diag("Statements before purge test: %d", stmt_count_before);
// Calculate how many statements to create to exceed cache limit by ~20%
// This ensures we trigger a purge even if some statements are deduplicated
int needed = CACHE_LIMIT + 200 - stmt_count_before;
if (needed < 200) needed = 200; // Create at least 200 statements
diag("Creating %d new statements to exceed cache limit and trigger purge...", needed);
// Create unique statements with different queries to force cache to exceed limit
// This triggers purge mechanism
int created = 0;
for (int i = 0; i < 100; i++) {
for (int i = 0; i < needed; i++) {
char stmt_name[64];
char query[128];
snprintf(stmt_name, sizeof(stmt_name), "verify_stmt_%d", i);
snprintf(query, sizeof(query), "SELECT %d::int", i);
snprintf(query, sizeof(query), "SELECT %d::int,'unique_%d'", i, i);
if (execute_prepared_stmt(backend_conn, stmt_name, query, {})) {
created++;
@ -383,16 +381,26 @@ bool test_concurrent_prepared_statements() {
diag(" Statements after test: %d", stmt_count_after);
diag(" Statements purged: %d", purged);
// Verify purge occurred and count is at/below limit
if (stmt_count_after <= CACHE_LIMIT && purged > 0) {
diag("PASS: Purge mechanism is WORKING - %d statements purged to enforce limit", purged);
diag(" Final count (%d) is at/below cache limit (%d)", stmt_count_after, CACHE_LIMIT);
if (!purge_verified) purge_verified = true;
// Verify purge occurred:
// 1. Final count is at/below cache limit (enforcement worked)
// 2. At least some statements were purged (mechanism activated)
if (stmt_count_after <= CACHE_LIMIT) {
diag("PASS: Cache limit ENFORCED - final count (%d) <= limit (%d)",
stmt_count_after, CACHE_LIMIT);
purge_verified = true;
} else {
diag("WARN: Cache limit NOT enforced - final count (%d) exceeds limit (%d)",
stmt_count_after, CACHE_LIMIT);
purge_verified = false;
}
if (purged > 0) {
diag("PASS: Purge mechanism ACTIVATED - %d statements purged", purged);
} else {
diag("INFO: No statements were purged (count may not have exceeded limit during test)");
}
} else {
diag("Could not query statement count after creating verification statements: %s",
diag("FAIL: Could not query statement count after creating verification statements: %s",
PQerrorMessage(admin_conn.get()));
return false;
}

Loading…
Cancel
Save