diff options
Diffstat (limited to 'src/test/isolation/isolationtester.c')
-rw-r--r-- | src/test/isolation/isolationtester.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/test/isolation/isolationtester.c b/src/test/isolation/isolationtester.c index b50c1897324..f80261c0229 100644 --- a/src/test/isolation/isolationtester.c +++ b/src/test/isolation/isolationtester.c @@ -30,6 +30,10 @@ static int *backend_pids = NULL; static const char **backend_pid_strs = NULL; static int nconns = 0; +/* Maximum time to wait before giving up on a step (in usec) */ +static int64 max_step_wait = 300 * USECS_PER_SEC; + + static void run_testspec(TestSpec *testspec); static void run_all_permutations(TestSpec *testspec); static void run_all_permutations_recurse(TestSpec *testspec, int nsteps, @@ -62,6 +66,7 @@ int main(int argc, char **argv) { const char *conninfo; + const char *env_wait; TestSpec *testspec; int i, j; @@ -103,6 +108,14 @@ main(int argc, char **argv) else conninfo = "dbname = postgres"; + /* + * If PGISOLATIONTIMEOUT is set in the environment, adopt its value (given + * in seconds) as the max time to wait for any one step to complete. + */ + env_wait = getenv("PGISOLATIONTIMEOUT"); + if (env_wait != NULL) + max_step_wait = ((int64) atoi(env_wait)) * USECS_PER_SEC; + /* Read the test spec from stdin */ spec_yyparse(); testspec = &parseresult; @@ -766,7 +779,7 @@ try_complete_step(TestSpec *testspec, Step *step, int flags) td += (int64) current_time.tv_usec - (int64) start_time.tv_usec; /* - * After 180 seconds, try to cancel the query. + * After max_step_wait microseconds, try to cancel the query. * * If the user tries to test an invalid permutation, we don't want * to hang forever, especially when this is running in the @@ -774,7 +787,7 @@ try_complete_step(TestSpec *testspec, Step *step, int flags) * failing, but remaining permutations and tests should still be * OK. */ - if (td > 180 * USECS_PER_SEC && !canceled) + if (td > max_step_wait && !canceled) { PGcancel *cancel = PQgetCancel(conn); @@ -783,7 +796,15 @@ try_complete_step(TestSpec *testspec, Step *step, int flags) char buf[256]; if (PQcancel(cancel, buf, sizeof(buf))) + { + /* + * print to stdout not stderr, as this should appear + * in the test case's results + */ + printf("isolationtester: canceling step %s after %d seconds\n", + step->name, (int) (td / USECS_PER_SEC)); canceled = true; + } else fprintf(stderr, "PQcancel failed: %s\n", buf); PQfreeCancel(cancel); @@ -791,16 +812,16 @@ try_complete_step(TestSpec *testspec, Step *step, int flags) } /* - * After 200 seconds, just give up and die. + * After twice max_step_wait, just give up and die. * * Since cleanup steps won't be run in this case, this may cause * later tests to fail. That stinks, but it's better than waiting * forever for the server to respond to the cancel. */ - if (td > 200 * USECS_PER_SEC) + if (td > 2 * max_step_wait) { - fprintf(stderr, "step %s timed out after 200 seconds\n", - step->name); + fprintf(stderr, "step %s timed out after %d seconds\n", + step->name, (int) (td / USECS_PER_SEC)); exit(1); } } |