From 4bde08d1a63976925a721ab2f4e000ad594fb34f Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 13 Feb 2021 11:19:09 -0600 Subject: [PATCH] LRU statement cache tests handle CockroackDB --- stmtcache/lru_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stmtcache/lru_test.go b/stmtcache/lru_test.go index 2d620905..a4108155 100644 --- a/stmtcache/lru_test.go +++ b/stmtcache/lru_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" "os" + "regexp" "testing" "time" @@ -239,7 +240,19 @@ func fetchServerStatements(t testing.TB, ctx context.Context, conn *pgconn.PgCon require.NoError(t, result.Err) var statements []string for _, r := range result.Rows { - statements = append(statements, string(r[0])) + statement := string(r[0]) + if conn.ParameterStatus("crdb_version") != "" { + if statement == "PREPARE AS select statement from pg_prepared_statements" { + // CockroachDB includes the currently running unnamed prepared statement while PostgreSQL does not. Ignore it. + continue + } + + // CockroachDB includes the "PREPARE ... AS" text in the statement even if it was prepared through the extended + // protocol will PostgreSQL does not. Normalize the statement. + re := regexp.MustCompile(`^PREPARE lrupsc[0-9_]+ AS `) + statement = re.ReplaceAllString(statement, "") + } + statements = append(statements, statement) } return statements }