mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
isolationtester: Use atexit()
Replace exit_nicely() calls with standard exit() and register the cleanup actions using atexit(). Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> Discussion: https://www.postgresql.org/message-id/flat/ec4135ba-84e9-28bf-b584-0e78d47448d5@2ndquadrant.com/
This commit is contained in:
parent
3913a40ff1
commit
be2e329f2e
@ -32,7 +32,6 @@ static int nconns = 0;
|
|||||||
/* In dry run only output permutations to be run by the tester. */
|
/* In dry run only output permutations to be run by the tester. */
|
||||||
static int dry_run = false;
|
static int dry_run = false;
|
||||||
|
|
||||||
static void exit_nicely(void) pg_attribute_noreturn();
|
|
||||||
static void run_testspec(TestSpec *testspec);
|
static void run_testspec(TestSpec *testspec);
|
||||||
static void run_all_permutations(TestSpec *testspec);
|
static void run_all_permutations(TestSpec *testspec);
|
||||||
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
|
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 isotesterNoticeProcessor(void *arg, const char *message);
|
||||||
static void blackholeNoticeProcessor(void *arg, const char *message);
|
static void blackholeNoticeProcessor(void *arg, const char *message);
|
||||||
|
|
||||||
/* close all connections and exit */
|
|
||||||
static void
|
static void
|
||||||
exit_nicely(void)
|
disconnect_atexit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < nconns; i++)
|
for (i = 0; i < nconns; i++)
|
||||||
PQfinish(conns[i]);
|
if (conns[i])
|
||||||
exit(1);
|
PQfinish(conns[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -140,7 +138,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "duplicate step name: %s\n",
|
fprintf(stderr, "duplicate step name: %s\n",
|
||||||
testspec->allsteps[i]->name);
|
testspec->allsteps[i]->name);
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +160,7 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
nconns = 1 + testspec->nsessions;
|
nconns = 1 + testspec->nsessions;
|
||||||
conns = calloc(nconns, sizeof(PGconn *));
|
conns = calloc(nconns, sizeof(PGconn *));
|
||||||
|
atexit(disconnect_atexit);
|
||||||
backend_pids = calloc(nconns, sizeof(*backend_pids));
|
backend_pids = calloc(nconns, sizeof(*backend_pids));
|
||||||
for (i = 0; i < nconns; i++)
|
for (i = 0; i < nconns; i++)
|
||||||
{
|
{
|
||||||
@ -170,7 +169,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "Connection %d to database failed: %s",
|
fprintf(stderr, "Connection %d to database failed: %s",
|
||||||
i, PQerrorMessage(conns[i]));
|
i, PQerrorMessage(conns[i]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -196,7 +195,7 @@ main(int argc, char **argv)
|
|||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "message level setup failed: %s", PQerrorMessage(conns[i]));
|
fprintf(stderr, "message level setup failed: %s", PQerrorMessage(conns[i]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
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",
|
fprintf(stderr, "backend pid query returned %d rows and %d columns, expected 1 row and 1 column",
|
||||||
PQntuples(res), PQnfields(res));
|
PQntuples(res), PQnfields(res));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "backend pid query failed: %s",
|
fprintf(stderr, "backend pid query failed: %s",
|
||||||
PQerrorMessage(conns[i]));
|
PQerrorMessage(conns[i]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
@ -254,7 +253,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "prepare of lock wait query failed: %s",
|
fprintf(stderr, "prepare of lock wait query failed: %s",
|
||||||
PQerrorMessage(conns[0]));
|
PQerrorMessage(conns[0]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
termPQExpBuffer(&wait_query);
|
termPQExpBuffer(&wait_query);
|
||||||
@ -265,9 +264,6 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
run_testspec(testspec);
|
run_testspec(testspec);
|
||||||
|
|
||||||
/* Clean up and exit */
|
|
||||||
for (i = 0; i < nconns; i++)
|
|
||||||
PQfinish(conns[i]);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +371,7 @@ run_named_permutations(TestSpec *testspec)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "undefined step \"%s\" specified in permutation\n",
|
fprintf(stderr, "undefined step \"%s\" specified in permutation\n",
|
||||||
p->stepnames[j]);
|
p->stepnames[j]);
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
steps[j] = *this;
|
steps[j] = *this;
|
||||||
}
|
}
|
||||||
@ -510,7 +506,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
|
|||||||
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));
|
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
@ -530,7 +526,7 @@ run_permutation(TestSpec *testspec, int nsteps, Step **steps)
|
|||||||
fprintf(stderr, "setup of session %s failed: %s",
|
fprintf(stderr, "setup of session %s failed: %s",
|
||||||
testspec->sessions[i]->name,
|
testspec->sessions[i]->name,
|
||||||
PQerrorMessage(conns[i + 1]));
|
PQerrorMessage(conns[i + 1]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
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",
|
fprintf(stdout, "failed to send query for step %s: %s\n",
|
||||||
step->name, PQerrorMessage(conn));
|
step->name, PQerrorMessage(conn));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to complete this step without blocking. */
|
/* Try to complete this step without blocking. */
|
||||||
@ -723,7 +719,7 @@ try_complete_step(Step *step, int flags)
|
|||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "invalid socket: %s", PQerrorMessage(conn));
|
fprintf(stderr, "invalid socket: %s", PQerrorMessage(conn));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&start_time, NULL);
|
gettimeofday(&start_time, NULL);
|
||||||
@ -741,7 +737,7 @@ try_complete_step(Step *step, int flags)
|
|||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
fprintf(stderr, "select failed: %s\n", strerror(errno));
|
fprintf(stderr, "select failed: %s\n", strerror(errno));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
else if (ret == 0) /* select() timeout: check for lock wait */
|
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",
|
fprintf(stderr, "lock wait query failed: %s",
|
||||||
PQerrorMessage(conns[0]));
|
PQerrorMessage(conns[0]));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
waiting = ((PQgetvalue(res, 0, 0))[0] == 't');
|
waiting = ((PQgetvalue(res, 0, 0))[0] == 't');
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@ -818,14 +814,14 @@ try_complete_step(Step *step, int flags)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "step %s timed out after 200 seconds\n",
|
fprintf(stderr, "step %s timed out after 200 seconds\n",
|
||||||
step->name);
|
step->name);
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!PQconsumeInput(conn)) /* select(): data available */
|
else if (!PQconsumeInput(conn)) /* select(): data available */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PQconsumeInput failed: %s\n",
|
fprintf(stderr, "PQconsumeInput failed: %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
exit_nicely();
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user