summaryrefslogtreecommitdiff
path: root/src/test/isolation/isolationtester.c
diff options
context:
space:
mode:
authorPeter Eisentraut2019-01-05 14:05:49 +0000
committerPeter Eisentraut2019-01-07 15:25:16 +0000
commitbe2e329f2e700032df087e08ac2103ba3d1fa811 (patch)
tree29fb9283cb1dfe8aa4ba00c680b8c60f4225d41d /src/test/isolation/isolationtester.c
parent3913a40ff104fd26f795c3d4c402ec27a1f86385 (diff)
isolationtester: Use atexit()
Replace exit_nicely() calls with standard exit() and register the cleanup actions using atexit(). Reviewed-by: Alvaro Herrera <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]/
Diffstat (limited to 'src/test/isolation/isolationtester.c')
-rw-r--r--src/test/isolation/isolationtester.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c
index 9134b0505eb..e59cf667bad 100644
--- a/src/test/isolation/isolationtester.c
+++ b/src/test/isolation/isolationtester.c
@@ -32,7 +32,6 @@ static int nconns = 0;
/* In dry run only output permutations to be run by the tester. */
static int dry_run = false;
-static void exit_nicely(void) pg_attribute_noreturn();
static void run_testspec(TestSpec *testspec);
static void run_all_permutations(TestSpec *testspec);
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
@@ -51,15 +50,14 @@ static void printResultSet(PGresult *res);
static void isotesterNoticeProcessor(void *arg, const char *message);
static void blackholeNoticeProcessor(void *arg, const char *message);
-/* close all connections and exit */
static void
-exit_nicely(void)
+disconnect_atexit(void)
{
int i;
for (i = 0; i < nconns; i++)
- PQfinish(conns[i]);
- exit(1);
+ if (conns[i])
+ PQfinish(conns[i]);
}
int
@@ -140,7 +138,7 @@ main(int argc, char **argv)
{
fprintf(stderr, "duplicate step name: %s\n",
testspec->allsteps[i]->name);
- exit_nicely();
+ exit(1);
}
}
@@ -162,6 +160,7 @@ main(int argc, char **argv)
*/
nconns = 1 + testspec->nsessions;
conns = calloc(nconns, sizeof(PGconn *));
+ atexit(disconnect_atexit);
backend_pids = calloc(nconns, sizeof(*backend_pids));
for (i = 0; i < nconns; i++)
{
@@ -170,7 +169,7 @@ main(int argc, char **argv)
{
fprintf(stderr, "Connection %d to database failed: %s",
i, PQerrorMessage(conns[i]));
- exit_nicely();
+ exit(1);
}
/*
@@ -196,7 +195,7 @@ main(int argc, char **argv)
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "message level setup failed: %s", PQerrorMessage(conns[i]));
- exit_nicely();
+ exit(1);
}
PQclear(res);
@@ -210,14 +209,14 @@ main(int argc, char **argv)
{
fprintf(stderr, "backend pid query returned %d rows and %d columns, expected 1 row and 1 column",
PQntuples(res), PQnfields(res));
- exit_nicely();
+ exit(1);
}
}
else
{
fprintf(stderr, "backend pid query failed: %s",
PQerrorMessage(conns[i]));
- exit_nicely();
+ exit(1);
}
PQclear(res);
}
@@ -254,7 +253,7 @@ main(int argc, char **argv)
{
fprintf(stderr, "prepare of lock wait query failed: %s",
PQerrorMessage(conns[0]));
- exit_nicely();
+ exit(1);
}
PQclear(res);
termPQExpBuffer(&wait_query);
@@ -265,9 +264,6 @@ main(int argc, char **argv)
*/
run_testspec(testspec);
- /* Clean up and exit */
- for (i = 0; i < nconns; i++)
- PQfinish(conns[i]);
return 0;
}
@@ -375,7 +371,7 @@ run_named_permutations(TestSpec *testspec)
{
fprintf(stderr, "undefined step \"%s\" specified in permutation\n",
p->stepnames[j]);
- exit_nicely();
+ exit(1);
}
steps[j] = *this;
}
@@ -510,7 +506,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));
- exit_nicely();
+ exit(1);
}
PQclear(res);
}
@@ -530,7 +526,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
fprintf(stderr, "setup of session %s failed: %s",
testspec->sessions[i]->name,
PQerrorMessage(conns[i + 1]));
- exit_nicely();
+ exit(1);
}
PQclear(res);
}
@@ -612,7 +608,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
{
fprintf(stdout, "failed to send query for step %s: %s\n",
step->name, PQerrorMessage(conn));
- exit_nicely();
+ exit(1);
}
/* Try to complete this step without blocking. */
@@ -723,7 +719,7 @@ try_complete_step(Step *step, int flags)
if (sock < 0)
{
fprintf(stderr, "invalid socket: %s", PQerrorMessage(conn));
- exit_nicely();
+ exit(1);
}
gettimeofday(&start_time, NULL);
@@ -741,7 +737,7 @@ try_complete_step(Step *step, int flags)
if (errno == EINTR)
continue;
fprintf(stderr, "select failed: %s\n", strerror(errno));
- exit_nicely();
+ exit(1);
}
else if (ret == 0) /* select() timeout: check for lock wait */
{
@@ -761,7 +757,7 @@ try_complete_step(Step *step, int flags)
{
fprintf(stderr, "lock wait query failed: %s",
PQerrorMessage(conns[0]));
- exit_nicely();
+ exit(1);
}
waiting = ((PQgetvalue(res, 0, 0))[0] == 't');
PQclear(res);
@@ -818,14 +814,14 @@ try_complete_step(Step *step, int flags)
{
fprintf(stderr, "step %s timed out after 200 seconds\n",
step->name);
- exit_nicely();
+ exit(1);
}
}
else if (!PQconsumeInput(conn)) /* select(): data available */
{
fprintf(stderr, "PQconsumeInput failed: %s\n",
PQerrorMessage(conn));
- exit_nicely();
+ exit(1);
}
}