Commit 845d335a authored by Tom Lane's avatar Tom Lane

Minor robustness improvements for isolationtester.

Notice and complain about PQcancel() failures.  Also, don't dump core if
an error PGresult doesn't contain severity and message subfields, as it
might not if it was generated by libpq itself.  (We have a longstanding
TODO item to improve that, but in the meantime isolationtester had better
cope.)

I tripped across the latter item while investigating a trouble report on
buildfarm member spoonbill.  As for the former, there's no evidence that
PQcancel failure is actually involved in spoonbill's problem, but it still
seems like a bad idea to ignore an error return code.
parent 89b661ba
...@@ -578,7 +578,8 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps) ...@@ -578,7 +578,8 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
{ {
char buf[256]; char buf[256];
PQcancel(cancel, buf, sizeof(buf)); if (!PQcancel(cancel, buf, sizeof(buf)))
fprintf(stderr, "PQcancel failed: %s\n", buf);
/* Be sure to consume the error message. */ /* Be sure to consume the error message. */
while ((res = PQgetResult(conn)) != NULL) while ((res = PQgetResult(conn)) != NULL)
...@@ -771,14 +772,26 @@ try_complete_step(Step * step, int flags) ...@@ -771,14 +772,26 @@ try_complete_step(Step * step, int flags)
printf("WARNING: this step had a leftover error message\n"); printf("WARNING: this step had a leftover error message\n");
printf("%s\n", step->errormsg); printf("%s\n", step->errormsg);
} }
/* Detail may contain xid values, so just show primary. */
step->errormsg = malloc(5 + /*
strlen(PQresultErrorField(res, PG_DIAG_SEVERITY)) + * Detail may contain XID values, so we want to just show
strlen(PQresultErrorField(res, * primary. Beware however that libpq-generated error results
PG_DIAG_MESSAGE_PRIMARY))); * may not contain subfields, only an old-style message.
sprintf(step->errormsg, "%s: %s", */
PQresultErrorField(res, PG_DIAG_SEVERITY), {
PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY)); const char *sev = PQresultErrorField(res,
PG_DIAG_SEVERITY);
const char *msg = PQresultErrorField(res,
PG_DIAG_MESSAGE_PRIMARY);
if (sev && msg)
{
step->errormsg = malloc(5 + strlen(sev) + strlen(msg));
sprintf(step->errormsg, "%s: %s", sev, msg);
}
else
step->errormsg = strdup(PQresultErrorMessage(res));
}
break; break;
default: default:
printf("unexpected result status: %s\n", printf("unexpected result status: %s\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment