From 9b9eaf08ab2dc22c691b22e59f1574e0f1bcc822 Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Fri, 23 Jan 2026 12:59:03 -0800 Subject: [PATCH] libpq_pipeline: Test the default protocol version In preparation for a future change to libpq's default protocol version, pin today's default (3.0) in the libpq_pipeline tests. Patch by Jelte Fennema-Nio, with some additional refactoring of the PQconnectdbParams() logic by me. Author: Jelte Fennema-Nio Discussion: https://postgr.es/m/DDPR5BPWH1RJ.1LWAK6QAURVAY%40jeltef.nl --- .../modules/libpq_pipeline/libpq_pipeline.c | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index 03371721460..0fb44be32ce 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -1328,17 +1328,13 @@ test_protocol_version(PGconn *conn) int nopts; PQconninfoOption *opts = PQconninfo(conn); int protocol_version; - int max_protocol_version_index; + int max_protocol_version_index = -1; int i; - /* - * Prepare keywords/vals arrays, copied from the existing connection, with - * an extra slot for 'max_protocol_version'. - */ + /* Prepare keywords/vals arrays, copied from the existing connection. */ nopts = 0; for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) nopts++; - nopts++; /* max_protocol_version */ nopts++; /* NULL terminator */ keywords = pg_malloc0(sizeof(char *) * nopts); @@ -1347,18 +1343,40 @@ test_protocol_version(PGconn *conn) i = 0; for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) { - if (opt->val) - { - keywords[i] = opt->keyword; - vals[i] = opt->val; - i++; - } + /* + * If the test already specified max_protocol_version, we want to + * replace it rather than attempting to override it. This matters when + * testing defaults, because empty option values at the end of the + * connection string won't replace earlier settings. + */ + if (strcmp(opt->keyword, "max_protocol_version") == 0) + max_protocol_version_index = i; + else if (!opt->val) + continue; + + keywords[i] = opt->keyword; + vals[i] = opt->val; + + i++; } - max_protocol_version_index = i; - keywords[i] = "max_protocol_version"; /* value is filled in below */ - i++; - keywords[i] = vals[i] = NULL; + Assert(max_protocol_version_index >= 0); + + /* + * Test default protocol_version + */ + vals[max_protocol_version_index] = ""; + conn = PQconnectdbParams(keywords, vals, false); + + if (PQstatus(conn) != CONNECTION_OK) + pg_fatal("Connection to database failed: %s", + PQerrorMessage(conn)); + + protocol_version = PQfullProtocolVersion(conn); + if (protocol_version != 30000) + pg_fatal("expected 30000, got %d", protocol_version); + + PQfinish(conn); /* * Test max_protocol_version=3.0