Skip to content

Commit c63f309

Browse files
committed
Allow isolation tests to specify multiple setup blocks.
Each setup block is run as a single PQexec submission, and some statements such as VACUUM cannot be combined with others in such a block. Backpatch to 9.2. Kevin Grittner and Tom Lane
1 parent 63f1ccd commit c63f309

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

src/test/isolation/README

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ subdirectory. A test specification consists of four parts, in this order:
4949
setup { <SQL> }
5050

5151
The given SQL block is executed once, in one session only, before running
52-
the test. Create any test tables or other required objects here. This
53-
part is optional.
52+
the test. Create any test tables or other required objects here. This
53+
part is optional. Multiple setup blocks are allowed if needed; each is
54+
run separately, in the given order. (The reason for allowing multiple
55+
setup blocks is that each block is run as a single PQexec submission,
56+
and some statements such as VACUUM cannot be combined with others in such
57+
a block.)
5458

5559
teardown { <SQL> }
5660

src/test/isolation/isolationtester.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ run_permutation(TestSpec * testspec, int nsteps, Step ** steps)
512512
printf("\n");
513513

514514
/* Perform setup */
515-
if (testspec->setupsql)
515+
for (i = 0; i < testspec->nsetupsqls; i++)
516516
{
517-
res = PQexec(conns[0], testspec->setupsql);
517+
res = PQexec(conns[0], testspec->setupsqls[i]);
518518
if (PQresultStatus(res) != PGRES_COMMAND_OK)
519519
{
520520
fprintf(stderr, "setup failed: %s", PQerrorMessage(conns[0]));

src/test/isolation/isolationtester.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ typedef struct
4242

4343
typedef struct
4444
{
45-
char *setupsql;
45+
char **setupsqls;
46+
int nsetupsqls;
4647
char *teardownsql;
4748
Session **sessions;
4849
int nsessions;

src/test/isolation/specparse.y

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ TestSpec parseresult; /* result of parsing is left here */
3535
} ptr_list;
3636
}
3737

38+
%type <ptr_list> setup_list
3839
%type <str> opt_setup opt_teardown
40+
%type <str> setup
3941
%type <ptr_list> step_list session_list permutation_list opt_permutation_list
4042
%type <ptr_list> string_list
4143
%type <session> session
@@ -48,12 +50,13 @@ TestSpec parseresult; /* result of parsing is left here */
4850
%%
4951

5052
TestSpec:
51-
opt_setup
53+
setup_list
5254
opt_teardown
5355
session_list
5456
opt_permutation_list
5557
{
56-
parseresult.setupsql = $1;
58+
parseresult.setupsqls = (char **) $1.elements;
59+
parseresult.nsetupsqls = $1.nelements;
5760
parseresult.teardownsql = $2;
5861
parseresult.sessions = (Session **) $3.elements;
5962
parseresult.nsessions = $3.nelements;
@@ -62,9 +65,28 @@ TestSpec:
6265
}
6366
;
6467

68+
setup_list:
69+
/* EMPTY */
70+
{
71+
$$.elements = NULL;
72+
$$.nelements = 0;
73+
}
74+
| setup_list setup
75+
{
76+
$$.elements = realloc($1.elements,
77+
($1.nelements + 1) * sizeof(void *));
78+
$$.elements[$1.nelements] = $2;
79+
$$.nelements = $1.nelements + 1;
80+
}
81+
;
82+
6583
opt_setup:
6684
/* EMPTY */ { $$ = NULL; }
67-
| SETUP sqlblock { $$ = $2; }
85+
| setup { $$ = $1; }
86+
;
87+
88+
setup:
89+
SETUP sqlblock { $$ = $2; }
6890
;
6991

7092
opt_teardown:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy