Skip to content

Commit 417ac9c

Browse files
committed
Improve test case stability
Given unlucky timing, some of the new tests added by commit bc32a12 can fail spuriously. We haven't seen such failures yet in buildfarm, but allegedly we can prevent them with this tweak. While at it, remove an unused injection point I (Álvaro) added. Author: Mihail Nikalayeu <mihailnikalayeu@gmail.com> Discussion: https://postgr.es/m/CADzfLwUc=jtSUEaQCtyt8zTeOJ-gHZ8=w_KJsVjDOYSLqaY9Lg@mail.gmail.com Discussion: https://postgr.es/m/CADzfLwV5oQq-Vg_VmG_o4SdL6yHjDoNO4T4pMtgJLzYGmYf74g@mail.gmail.com
1 parent 7169c0b commit 417ac9c

File tree

6 files changed

+45
-22
lines changed

6 files changed

+45
-22
lines changed

src/backend/executor/execIndexing.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,7 @@ check_exclusion_or_unique_constraint(Relation heap, Relation index,
945945
ExecDropSingleTupleTableSlot(existing_slot);
946946

947947
#ifdef USE_INJECTION_POINTS
948-
if (conflict)
949-
INJECTION_POINT("check-exclusion-or-unique-constraint-conflict", NULL);
950-
else
948+
if (!conflict)
951949
INJECTION_POINT("check-exclusion-or-unique-constraint-no-conflict", NULL);
952950
#endif
953951

src/backend/utils/time/snapmgr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ InvalidateCatalogSnapshot(void)
459459
pairingheap_remove(&RegisteredSnapshots, &CatalogSnapshot->ph_node);
460460
CatalogSnapshot = NULL;
461461
SnapshotResetXmin();
462+
INJECTION_POINT("pre-invalidate-catalog-snapshot-end", NULL);
462463
INJECTION_POINT("invalidate-catalog-snapshot-end", NULL);
463464
}
464465
}

src/test/modules/injection_points/expected/index-concurrently-upsert-predicate.out

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Parsed test spec with 4 sessions
1+
Parsed test spec with 5 sessions
22

3-
starting permutation: s3_start_create_index s1_start_upsert s4_wakeup_define_index_before_set_valid s2_start_upsert s4_wakeup_s1_from_invalidate_catalog_snapshot s4_wakeup_s2 s4_wakeup_s1
3+
starting permutation: s5_noop s3_start_create_index s1_start_upsert s4_wakeup_define_index_before_set_valid s2_start_upsert s5_wakeup_s1_from_invalidate_catalog_snapshot s4_wakeup_s2 s4_wakeup_s1
44
injection_points_attach
55
-----------------------
66

@@ -16,12 +16,16 @@ injection_points_attach
1616

1717
(1 row)
1818

19+
step s5_noop:
20+
<waiting ...>
1921
step s3_start_create_index:
2022
CREATE UNIQUE INDEX CONCURRENTLY tbl_pkey_special_duplicate ON test.tbl(abs(i)) WHERE i < 10000;
2123
<waiting ...>
24+
s1: NOTICE: notice triggered for injection point pre-invalidate-catalog-snapshot-end
2225
step s1_start_upsert:
2326
INSERT INTO test.tbl VALUES(13,now()) ON CONFLICT (abs(i)) WHERE i < 100 DO UPDATE SET updated_at = now();
2427
<waiting ...>
28+
step s5_noop: <... completed>
2529
step s4_wakeup_define_index_before_set_valid:
2630
SELECT injection_points_detach('define-index-before-set-valid');
2731
SELECT injection_points_wakeup('define-index-before-set-valid');
@@ -39,7 +43,7 @@ injection_points_wakeup
3943
step s2_start_upsert:
4044
INSERT INTO test.tbl VALUES(13,now()) ON CONFLICT (abs(i)) WHERE i < 100 DO UPDATE SET updated_at = now();
4145
<waiting ...>
42-
step s4_wakeup_s1_from_invalidate_catalog_snapshot:
46+
step s5_wakeup_s1_from_invalidate_catalog_snapshot:
4347
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
4448
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
4549

@@ -81,6 +85,7 @@ injection_points_wakeup
8185

8286
(1 row)
8387

88+
s1: NOTICE: notice triggered for injection point pre-invalidate-catalog-snapshot-end
8489
step s1_start_upsert: <... completed>
8590
step s2_start_upsert: <... completed>
8691
step s3_start_create_index: <... completed>

src/test/modules/injection_points/expected/index-concurrently-upsert.out

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Parsed test spec with 4 sessions
1+
Parsed test spec with 5 sessions
22

3-
starting permutation: s3_start_create_index s1_start_upsert s4_wakeup_define_index_before_set_valid s2_start_upsert s4_wakeup_s1_from_invalidate_catalog_snapshot s4_wakeup_s2 s4_wakeup_s1
3+
starting permutation: s5_noop s3_start_create_index s1_start_upsert s4_wakeup_define_index_before_set_valid s2_start_upsert s5_wakeup_s1_from_invalidate_catalog_snapshot s4_wakeup_s2 s4_wakeup_s1
44
injection_points_attach
55
-----------------------
66

@@ -16,12 +16,16 @@ injection_points_attach
1616

1717
(1 row)
1818

19+
step s5_noop:
20+
<waiting ...>
1921
step s3_start_create_index:
2022
CREATE UNIQUE INDEX CONCURRENTLY tbl_pkey_duplicate ON test.tbl(i);
2123
<waiting ...>
24+
s1: NOTICE: notice triggered for injection point pre-invalidate-catalog-snapshot-end
2225
step s1_start_upsert:
2326
INSERT INTO test.tbl VALUES (13,now()) ON CONFLICT (i) DO UPDATE SET updated_at = now();
2427
<waiting ...>
28+
step s5_noop: <... completed>
2529
step s4_wakeup_define_index_before_set_valid:
2630
SELECT injection_points_detach('define-index-before-set-valid');
2731
SELECT injection_points_wakeup('define-index-before-set-valid');
@@ -39,7 +43,7 @@ injection_points_wakeup
3943
step s2_start_upsert:
4044
INSERT INTO test.tbl VALUES (13,now()) ON CONFLICT (i) DO UPDATE SET updated_at = now();
4145
<waiting ...>
42-
step s4_wakeup_s1_from_invalidate_catalog_snapshot:
46+
step s5_wakeup_s1_from_invalidate_catalog_snapshot:
4347
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
4448
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
4549

@@ -81,6 +85,7 @@ injection_points_wakeup
8185

8286
(1 row)
8387

88+
s1: NOTICE: notice triggered for injection point pre-invalidate-catalog-snapshot-end
8489
step s1_start_upsert: <... completed>
8590
step s2_start_upsert: <... completed>
8691
step s3_start_create_index: <... completed>

src/test/modules/injection_points/specs/index-concurrently-upsert-predicate.spec

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# - s2: UPSERT the same tuple
66
# - s3: CREATE UNIQUE INDEX CONCURRENTLY (with a predicate)
77
#
8-
# - s4: control concurrency via injection points
8+
# - s4 and s5: control concurrency via injection points
99

1010
setup
1111
{
@@ -27,6 +27,7 @@ setup
2727
{
2828
SELECT injection_points_set_local();
2929
SELECT injection_points_attach('check-exclusion-or-unique-constraint-no-conflict', 'wait');
30+
SELECT injection_points_attach('pre-invalidate-catalog-snapshot-end', 'notice');
3031
SELECT injection_points_attach('invalidate-catalog-snapshot-end', 'wait');
3132
}
3233
step s1_start_upsert
@@ -62,11 +63,6 @@ step s4_wakeup_s1
6263
SELECT injection_points_detach('check-exclusion-or-unique-constraint-no-conflict');
6364
SELECT injection_points_wakeup('check-exclusion-or-unique-constraint-no-conflict');
6465
}
65-
step s4_wakeup_s1_from_invalidate_catalog_snapshot
66-
{
67-
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
68-
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
69-
}
7066
step s4_wakeup_s2
7167
{
7268
SELECT injection_points_detach('exec-insert-before-insert-speculative');
@@ -78,11 +74,22 @@ step s4_wakeup_define_index_before_set_valid
7874
SELECT injection_points_wakeup('define-index-before-set-valid');
7975
}
8076

77+
session s5
78+
step s5_noop
79+
{
80+
}
81+
step s5_wakeup_s1_from_invalidate_catalog_snapshot
82+
{
83+
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
84+
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
85+
}
86+
8187
permutation
88+
s5_noop(s1_start_upsert notices 1)
8289
s3_start_create_index(s1_start_upsert, s2_start_upsert)
8390
s1_start_upsert
8491
s4_wakeup_define_index_before_set_valid
8592
s2_start_upsert(s1_start_upsert)
86-
s4_wakeup_s1_from_invalidate_catalog_snapshot
93+
s5_wakeup_s1_from_invalidate_catalog_snapshot
8794
s4_wakeup_s2
8895
s4_wakeup_s1

src/test/modules/injection_points/specs/index-concurrently-upsert.spec

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ setup
2626
{
2727
SELECT injection_points_set_local();
2828
SELECT injection_points_attach('check-exclusion-or-unique-constraint-no-conflict', 'wait');
29+
SELECT injection_points_attach('pre-invalidate-catalog-snapshot-end', 'notice');
2930
SELECT injection_points_attach('invalidate-catalog-snapshot-end', 'wait');
3031
}
3132
step s1_start_upsert
@@ -61,11 +62,6 @@ step s4_wakeup_s1
6162
SELECT injection_points_detach('check-exclusion-or-unique-constraint-no-conflict');
6263
SELECT injection_points_wakeup('check-exclusion-or-unique-constraint-no-conflict');
6364
}
64-
step s4_wakeup_s1_from_invalidate_catalog_snapshot
65-
{
66-
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
67-
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
68-
}
6965
step s4_wakeup_s2
7066
{
7167
SELECT injection_points_detach('exec-insert-before-insert-speculative');
@@ -77,11 +73,22 @@ step s4_wakeup_define_index_before_set_valid
7773
SELECT injection_points_wakeup('define-index-before-set-valid');
7874
}
7975

76+
session s5
77+
step s5_noop
78+
{
79+
}
80+
step s5_wakeup_s1_from_invalidate_catalog_snapshot
81+
{
82+
SELECT injection_points_detach('invalidate-catalog-snapshot-end');
83+
SELECT injection_points_wakeup('invalidate-catalog-snapshot-end');
84+
}
85+
8086
permutation
87+
s5_noop(s1_start_upsert notices 1)
8188
s3_start_create_index(s1_start_upsert, s2_start_upsert)
8289
s1_start_upsert
8390
s4_wakeup_define_index_before_set_valid
8491
s2_start_upsert(s1_start_upsert)
85-
s4_wakeup_s1_from_invalidate_catalog_snapshot
92+
s5_wakeup_s1_from_invalidate_catalog_snapshot
8693
s4_wakeup_s2
8794
s4_wakeup_s1

0 commit comments

Comments
 (0)