|
8 | 8 | use TestLib;
|
9 | 9 |
|
10 | 10 | use Fcntl qw(:seek);
|
11 |
| -use Test::More tests => 80; |
| 11 | +use Test::More tests => 272; |
12 | 12 |
|
13 | 13 | my ($node, $result);
|
14 | 14 |
|
|
60 | 60 | "verify_heapam('test', skip := 'all-frozen')",
|
61 | 61 | "all-frozen corrupted table skipping all-frozen");
|
62 | 62 |
|
| 63 | +# |
| 64 | +# Check a sequence with no corruption. The current implementation of sequences |
| 65 | +# doesn't require its own test setup, since sequences are really just heap |
| 66 | +# tables under-the-hood. To guard against future implementation changes made |
| 67 | +# without remembering to update verify_heapam, we create and exercise a |
| 68 | +# sequence, checking along the way that it passes corruption checks. |
| 69 | +# |
| 70 | +fresh_test_sequence('test_seq'); |
| 71 | +check_all_options_uncorrupted('test_seq', 'plain'); |
| 72 | +advance_test_sequence('test_seq'); |
| 73 | +check_all_options_uncorrupted('test_seq', 'plain'); |
| 74 | +set_test_sequence('test_seq'); |
| 75 | +check_all_options_uncorrupted('test_seq', 'plain'); |
| 76 | +reset_test_sequence('test_seq'); |
| 77 | +check_all_options_uncorrupted('test_seq', 'plain'); |
| 78 | + |
63 | 79 | # Returns the filesystem path for the named relation.
|
64 | 80 | sub relation_filepath
|
65 | 81 | {
|
@@ -110,6 +126,56 @@ sub fresh_test_table
|
110 | 126 | ));
|
111 | 127 | }
|
112 | 128 |
|
| 129 | +# Create a test sequence of the given name. |
| 130 | +sub fresh_test_sequence |
| 131 | +{ |
| 132 | + my ($seqname) = @_; |
| 133 | + |
| 134 | + return $node->safe_psql( |
| 135 | + 'postgres', qq( |
| 136 | + DROP SEQUENCE IF EXISTS $seqname CASCADE; |
| 137 | + CREATE SEQUENCE $seqname |
| 138 | + INCREMENT BY 13 |
| 139 | + MINVALUE 17 |
| 140 | + START WITH 23; |
| 141 | + SELECT nextval('$seqname'); |
| 142 | + SELECT setval('$seqname', currval('$seqname') + nextval('$seqname')); |
| 143 | + )); |
| 144 | +} |
| 145 | + |
| 146 | +# Call SQL functions to increment the sequence |
| 147 | +sub advance_test_sequence |
| 148 | +{ |
| 149 | + my ($seqname) = @_; |
| 150 | + |
| 151 | + return $node->safe_psql( |
| 152 | + 'postgres', qq( |
| 153 | + SELECT nextval('$seqname'); |
| 154 | + )); |
| 155 | +} |
| 156 | + |
| 157 | +# Call SQL functions to set the sequence |
| 158 | +sub set_test_sequence |
| 159 | +{ |
| 160 | + my ($seqname) = @_; |
| 161 | + |
| 162 | + return $node->safe_psql( |
| 163 | + 'postgres', qq( |
| 164 | + SELECT setval('$seqname', 102); |
| 165 | + )); |
| 166 | +} |
| 167 | + |
| 168 | +# Call SQL functions to reset the sequence |
| 169 | +sub reset_test_sequence |
| 170 | +{ |
| 171 | + my ($seqname) = @_; |
| 172 | + |
| 173 | + return $node->safe_psql( |
| 174 | + 'postgres', qq( |
| 175 | + ALTER SEQUENCE $seqname RESTART WITH 51 |
| 176 | + )); |
| 177 | +} |
| 178 | + |
113 | 179 | # Stops the test node, corrupts the first page of the named relation, and
|
114 | 180 | # restarts the node.
|
115 | 181 | sub corrupt_first_page
|
|
0 commit comments