@@ -3,28 +3,42 @@ src/test/isolation/README
3
3
Isolation tests
4
4
===============
5
5
6
- This directory contains a set of tests for the serializable isolation level.
7
- Testing isolation requires running multiple overlapping transactions,
8
- which requires multiple concurrent connections, and therefore can't be
9
- tested using the normal pg_regress program.
6
+ This directory contains a set of tests for concurrent behaviors in
7
+ PostgreSQL. These tests require running multiple interacting transactions,
8
+ which requires management of multiple concurrent connections, and therefore
9
+ can't be tested using the normal pg_regress program. The name "isolation"
10
+ comes from the fact that the original motivation was to test the
11
+ serializable isolation level; but tests for other sorts of concurrent
12
+ behaviors have been added as well.
10
13
11
14
To run the tests, you need to have a server running at the default port
12
15
expected by libpq. (You can set PGPORT and so forth in your environment
13
16
to control this.) Then run
14
17
gmake installcheck
15
- Note that the prepared-transactions test will not pass unless you have
16
- the server's max_prepared_transactions parameter set to at least 3.
17
-
18
- To represent a test with overlapping transactions, we use a test specification
19
- file with a custom syntax, which is described in the next section.
18
+ To run just specific test(s), you can do something like
19
+ ./pg_isolation_regress fk-contention fk-deadlock
20
+ (look into the specs/ subdirectory to see the available tests).
21
+
22
+ Note that the prepared-transactions test requires the server's
23
+ max_prepared_transactions parameter to be set to at least 3. We have
24
+ provided a variant expected-output file that allows the test to "pass"
25
+ when max_prepared_transactions has its default value of zero, but of
26
+ course that is not really exercising the feature.
27
+
28
+ To define tests with overlapping transactions, we use test specification
29
+ files with a custom syntax, which is described in the next section. To add
30
+ a new test, place a spec file in the specs/ subdirectory, add the expected
31
+ output in the expected/ subdirectory, and add the test's name to the
32
+ isolation_schedule file.
20
33
21
34
isolationtester is a program that uses libpq to open multiple connections,
22
35
and executes a test specified by a spec file. A libpq connection string
23
36
specifies the server and database to connect to; defaults derived from
24
37
environment variables are used otherwise.
25
38
26
39
pg_isolation_regress is a tool similar to pg_regress, but instead of using
27
- psql to execute a test, it uses isolationtester.
40
+ psql to execute a test, it uses isolationtester. It accepts all the same
41
+ command-line arguments as pg_regress.
28
42
29
43
30
44
Test specification
@@ -36,48 +50,65 @@ subdirectory. A test specification consists of four parts, in this order:
36
50
setup { <SQL> }
37
51
38
52
The given SQL block is executed once, in one session only, before running
39
- the test. Create any test tables or such objects here. This part is
40
- optional.
53
+ the test. Create any test tables or other required objects here. This
54
+ part is optional.
41
55
42
56
teardown { <SQL> }
43
57
44
58
The teardown SQL block is executed once after the test is finished. Use
45
- this to clean up, e.g dropping any test tables. This part is optional.
59
+ this to clean up in preparation for the next permutation, e.g dropping
60
+ any test tables created by setup. This part is optional.
46
61
47
62
session "<name>"
48
63
49
- Each session is executed in a separate connection. A session consists
50
- of four parts: setup, teardown and one or more steps. The per-session
64
+ There are normally several "session" parts in a spec file. Each
65
+ session is executed in its own connection. A session part consists
66
+ of three parts: setup, teardown and one or more "steps". The per-session
51
67
setup and teardown parts have the same syntax as the per-test setup and
52
- teardown described above, but they are executed in every session,
53
- before and after each permutation. The setup part typically contains a
54
- "BEGIN" command to begin a transaction.
68
+ teardown described above, but they are executed in each session. The
69
+ setup part typically contains a "BEGIN" command to begin a transaction.
55
70
56
- Each step has a syntax of
71
+ Each step has the syntax
57
72
58
73
step "<name>" { <SQL> }
59
74
60
- where <name> is a unique name identifying this step, and SQL is a SQL
61
- statement (or statements, separated by semicolons) that is executed in the
62
- step .
75
+ where <name> is a name identifying this step, and SQL is a SQL statement
76
+ (or statements, separated by semicolons) that is executed in the step.
77
+ Step names must be unique across the whole spec file .
63
78
64
79
permutation "<step name>" ...
65
80
66
81
A permutation line specifies a list of steps that are run in that order.
67
- If no permutation lines are given, the test program automatically generates
68
- all possible overlapping orderings of the given sessions.
82
+ Any number of permutation lines can appear. If no permutation lines are
83
+ given, the test program automatically generates all possible orderings
84
+ of the steps from each session (running the steps of any one session in
85
+ order). Note that the list of steps in a manually specified
86
+ "permutation" line doesn't actually have to be a permutation of the
87
+ available steps; it could for instance repeat some steps more than once,
88
+ or leave others out.
69
89
70
90
Lines beginning with a # are considered comments.
71
91
92
+ For each permutation of the session steps (whether these are manually
93
+ specified in the spec file, or automatically generated), the isolation
94
+ tester runs the main setup part, then per-session setup parts, then
95
+ the selected session steps, then per-session teardown, then the main
96
+ teardown script. Each selected step is sent to the connection associated
97
+ with its session.
98
+
72
99
73
100
Support for blocking commands
74
101
=============================
75
102
76
- Each spec may contain commands that block until further action has been taken
103
+ Each step may contain commands that block until further action has been taken
77
104
(most likely, some other session runs a step that unblocks it or causes a
78
- deadlock). Such a spec needs to be careful to manually specify valid
105
+ deadlock). A test that uses this ability must manually specify valid
79
106
permutations, i.e. those that would not expect a blocked session to execute a
80
- command. If the spec fails to follow that rule, the spec is aborted.
107
+ command. If the test fails to follow that rule, the test is aborted.
108
+
109
+ Currently, at most one step can be waiting at a time. As long as one
110
+ step is waiting, subsequent steps are run to completion synchronously.
81
111
82
- Only one command can be waiting at a time. As long as one command is waiting,
83
- other commands are run to completion synchronously.
112
+ Note that isolationtester recognizes that a command has blocked by looking
113
+ to see if it is shown as waiting in the pg_locks view; therefore, only
114
+ blocks on heavyweight locks will be detected.
0 commit comments