Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 845d335

Browse files
committed
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.
1 parent 89b661b commit 845d335

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/test/isolation/isolationtester.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
578578
{
579579
char buf[256];
580580

581-
PQcancel(cancel, buf, sizeof(buf));
581+
if (!PQcancel(cancel, buf, sizeof(buf)))
582+
fprintf(stderr, "PQcancel failed: %s\n", buf);
582583

583584
/* Be sure to consume the error message. */
584585
while ((res = PQgetResult(conn)) != NULL)
@@ -771,14 +772,26 @@ try_complete_step(Step * step, int flags)
771772
printf("WARNING: this step had a leftover error message\n");
772773
printf("%s\n", step->errormsg);
773774
}
774-
/* Detail may contain xid values, so just show primary. */
775-
step->errormsg = malloc(5 +
776-
strlen(PQresultErrorField(res, PG_DIAG_SEVERITY)) +
777-
strlen(PQresultErrorField(res,
778-
PG_DIAG_MESSAGE_PRIMARY)));
779-
sprintf(step->errormsg, "%s: %s",
780-
PQresultErrorField(res, PG_DIAG_SEVERITY),
781-
PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY));
775+
776+
/*
777+
* Detail may contain XID values, so we want to just show
778+
* primary. Beware however that libpq-generated error results
779+
* may not contain subfields, only an old-style message.
780+
*/
781+
{
782+
const char *sev = PQresultErrorField(res,
783+
PG_DIAG_SEVERITY);
784+
const char *msg = PQresultErrorField(res,
785+
PG_DIAG_MESSAGE_PRIMARY);
786+
787+
if (sev && msg)
788+
{
789+
step->errormsg = malloc(5 + strlen(sev) + strlen(msg));
790+
sprintf(step->errormsg, "%s: %s", sev, msg);
791+
}
792+
else
793+
step->errormsg = strdup(PQresultErrorMessage(res));
794+
}
782795
break;
783796
default:
784797
printf("unexpected result status: %s\n",

0 commit comments

Comments
 (0)