summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2021-12-13 12:02:58 -0800
committerAndres Freund <andres@anarazel.de>2021-12-13 12:02:58 -0800
commitdbc5cdd5cbb8b9f98b880c0e49d613729bf1b839 (patch)
treea5cef44d41fd9964ee59d9635b3341f85b1d8fd8 /src
parent30d57136fcef8d1c9c0c8e6701bc1f083c9557ea (diff)
isolationtester: append session name to application_name.
When writing / debugging an isolation test it sometimes is useful to see which session holds what lock etc. To make it easier, both as part of spec files and interactively, append the session name to application_name. Since b1907d688 application_name already contains the test name, this appends the session's name to that. insert-conflict-specconflict did something like this manually, which can now be removed. As we have done lately with other test infrastructure improvements, backpatch this change, to make it easier to backpatch tests. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Michael Paquier <michael@paquier.xyz> Reviewed-By: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/20211211012052.2blmzcmxnxqawd2z@alap3.anarazel.de Backpatch: 10-, to make backpatching of tests easier.
Diffstat (limited to 'src')
-rw-r--r--src/test/isolation/isolationtester.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index f25c3127463..8c106ce506e 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -156,10 +156,14 @@ main(int argc, char **argv)
for (i = 0; i < nconns; i++)
{
+ const char *sessionname;
+
if (i == 0)
- conns[i].sessionname = "control connection";
+ sessionname = "control connection";
else
- conns[i].sessionname = testspec->sessions[i - 1]->name;
+ sessionname = testspec->sessions[i - 1]->name;
+
+ conns[i].sessionname = sessionname;
conns[i].conn = PQconnectdb(conninfo);
if (PQstatus(conns[i].conn) != CONNECTION_OK)
@@ -184,6 +188,26 @@ main(int argc, char **argv)
blackholeNoticeProcessor,
NULL);
+ /*
+ * Similarly, append the session name to application_name to make it
+ * easier to map spec file sessions to log output and
+ * pg_stat_activity. The reason to append instead of just setting the
+ * name is that we don't know the name of the test currently running.
+ */
+ res = PQexecParams(conns[i].conn,
+ "SELECT set_config('application_name',\n"
+ " current_setting('application_name') || '/' || $1,\n"
+ " false)",
+ 1, NULL,
+ &sessionname,
+ NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ {
+ fprintf(stderr, "setting of application name failed: %s",
+ PQerrorMessage(conns[i].conn));
+ exit(1);
+ }
+
/* Save each connection's backend PID for subsequent use. */
conns[i].backend_pid = PQbackendPID(conns[i].conn);
conns[i].backend_pid_str = psprintf("%d", conns[i].backend_pid);