backpatch "Set application_name per-test in isolation and ecpg tests."
authorAndres Freund <[email protected]>
Mon, 13 Dec 2021 19:39:52 +0000 (11:39 -0800)
committerAndres Freund <[email protected]>
Mon, 13 Dec 2021 19:39:52 +0000 (11:39 -0800)
We started to backpatch test infrastructure improvements more aggressively to
make it easier to backpatch test. A proposed isolationtester improvement has a
dependency on b1907d688, backpatch b1907d688 to make it easier to subsequently
backpatch the new proposed isolationtester change.

Discussion: https://postgr.es/m/861977.1639421872@sss.pgh.pa.us
Backpatch: 10-12, the commit already is in 13-HEAD

src/interfaces/ecpg/test/pg_regress_ecpg.c
src/test/isolation/isolation_main.c
src/test/regress/pg_regress.c

index 066dbcc89777044d1b8f7e6361f9fc6ea55f8d82..75345f1f3b8cde38516e38cd5bdf86143a23b229 100644 (file)
@@ -95,6 +95,7 @@ ecpg_start_test(const char *testname,
                expectfile_source[MAXPGPATH];
    char        cmd[MAXPGPATH * 3];
    char       *testname_dash;
+   char       *appnameenv;
 
    snprintf(inprg, sizeof(inprg), "%s/%s", inputdir, testname);
 
@@ -144,6 +145,9 @@ ecpg_start_test(const char *testname,
             outfile_stdout,
             outfile_stderr);
 
+   appnameenv = psprintf("PGAPPNAME=ecpg/%s", testname_dash);
+   putenv(appnameenv);
+
    pid = spawn_process(cmd);
 
    if (pid == INVALID_PID)
@@ -153,6 +157,10 @@ ecpg_start_test(const char *testname,
        exit(2);
    }
 
+   unsetenv("PGAPPNAME");
+   free(appnameenv);
+
+   free(testname_dash);
    free(outfile_stdout);
    free(outfile_stderr);
    free(outfile_source);
index 294bf30470ac2ec6d9be245042387f0e89658848..b9e253377268e78276aeffb51d33400e9cd91292 100644 (file)
@@ -36,6 +36,7 @@ isolation_start_test(const char *testname,
    char        expectfile[MAXPGPATH];
    char        psql_cmd[MAXPGPATH * 3];
    size_t      offset = 0;
+   char       *appnameenv;
 
    /* need to do the path lookup here, check isolation_init() for details */
    if (!looked_up_isolation_exec)
@@ -97,6 +98,9 @@ isolation_start_test(const char *testname,
        exit(2);
    }
 
+   appnameenv = psprintf("PGAPPNAME=isolation/%s", testname);
+   putenv(appnameenv);
+
    pid = spawn_process(psql_cmd);
 
    if (pid == INVALID_PID)
@@ -106,6 +110,9 @@ isolation_start_test(const char *testname,
        exit(2);
    }
 
+   unsetenv("PGAPPNAME");
+   free(appnameenv);
+
    return pid;
 }
 
index c38594385fa3bf24c170b7fc40beb353cb2c6005..9b3b5d82d8a786f133bd8b1c1f086a3ccb4cf9a1 100644 (file)
@@ -726,6 +726,10 @@ doputenv(const char *var, const char *val)
 static void
 initialize_environment(void)
 {
+   /*
+    * Set default application_name.  (The test_function may choose to
+    * override this, but if it doesn't, we have something useful in place.)
+    */
    putenv("PGAPPNAME=pg_regress");
 
    if (nolocale)