Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0a55f4

Browse files
committed
Add TAP test to automate the equivalent of check_guc
src/backend/utils/misc/check_guc is a script that cross-checks theconsistency of the GUCs with postgresql.conf.sample, making sure thatits format is in line with what guc.c has. It has never been runautomatically, and has rotten over the years, creating a lot of falsepositives as per a report from Justin Pryzby.d10e41d has introduced a SQL function to publish the most relevant flagsassociated to a GUC, with tests added in the main regression test suiteto make sure that we avoid most of the inconsistencies in the GUCsettings, based on recent reports, but there was nothing able tocross-check postgresql.conf.sample with the contents of guc.c.This commit adds a TAP test that covers the remaining gap. It emulatesthe most relevant checks that check_guc does, so as any format mistakesare detected in postgresql.conf.sample at development stage, with thefollowing checks:- Check that parameters marked as NOT_IN_SAMPLE are not in the samplefile.- Check that there are no dead entries in postgresql.conf.sample forparameters not marked as NOT_IN_SAMPLE.- Check that no parameters are missing from the sample file if listed inguc.c without NOT_IN_SAMPLE.The idea of building a list of the GUCs by parsing the sample file comesfrom Justin, and he wrote the regex used in the patch to find all theGUCs (this same formatting rule basically applies for the last 20~ yearsor so). In order to test this patch, I have played with manualmodifications of postgresql.conf.sample and guc.c, making sure that wedetect problems with the GUC rules and the sample file format.The test is located in src/test/modules/test_misc, which is the bestlocation I could think about for such sanity checks.Reviewed-by: Justin PryzbyDiscussion:https://postgr.es/m/Yf9YGSwPiMu0c7fP@paquier.xyz
1 parentd5c2a91 commitb0a55f4

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Tests to cross-check the consistency of GUC parameters with
2+
# postgresql.conf.sample..
3+
4+
use strict;
5+
use warnings;
6+
use PostgreSQL::Test::Cluster;
7+
use PostgreSQL::Test::Utils;
8+
use Test::Moretests=> 3;
9+
10+
my$node = PostgreSQL::Test::Cluster->new('main');
11+
$node->init;
12+
$node->start;
13+
14+
# Grab the names of all the parameters that can be listed in the
15+
# configuration sample file. config_file is an exception. It is not
16+
# in postgresql.conf.sample but is part of the lists from guc.c.
17+
my$all_params =$node->safe_psql(
18+
'postgres',
19+
"SELECT name
20+
FROM pg_settings
21+
WHERE NOT 'NOT_IN_SAMPLE' = ANY (pg_settings_get_flags(name)) AND
22+
name <> 'config_file'
23+
ORDER BY 1");
24+
# Note the lower-case conversion, for consistency.
25+
my@all_params_array =split("\n",lc($all_params));
26+
27+
# Grab the names of all parameters marked as NOT_IN_SAMPLE.
28+
my$not_in_sample =$node->safe_psql(
29+
'postgres',
30+
"SELECT name
31+
FROM pg_settings
32+
WHERE 'NOT_IN_SAMPLE' = ANY (pg_settings_get_flags(name))
33+
ORDER BY 1");
34+
my@not_in_sample_array =split("\n",lc($not_in_sample));
35+
36+
# Find the location of postgresql.conf.sample, based on the information
37+
# provided by pg_config.
38+
my$sample_file =
39+
$node->config_data('--sharedir') .'/postgresql.conf.sample';
40+
41+
# List of all the GUCs found in the sample file.
42+
my@gucs_in_file;
43+
44+
# Read the sample file line-by-line, checking its contents to build a list
45+
# of everything known as a GUC.
46+
my$num_tests = 0;
47+
open(my$contents,'<',$sample_file)
48+
||die"Could not open$sample_file:$!";
49+
while (my$line = <$contents>)
50+
{
51+
# Check if this line matches a GUC parameter:
52+
# - Each parameter is preceded by "#", but not "# " in the sample
53+
# file.
54+
# - Valid configuration options are followed immediately by " = ",
55+
# with one space before and after the equal sign.
56+
if ($line =~m/^#?([_[:alpha:]]+) = .*/)
57+
{
58+
# Lower-case conversion matters for some of the GUCs.
59+
my$param_name =lc($1);
60+
61+
# Ignore some exceptions.
62+
nextif$param_nameeq"include";
63+
nextif$param_nameeq"include_dir";
64+
nextif$param_nameeq"include_if_exists";
65+
66+
# Update the list of GUCs found in the sample file, for the
67+
# follow-up tests.
68+
push@gucs_in_file,$param_name;
69+
}
70+
}
71+
72+
close$contents;
73+
74+
# Cross-check that all the GUCs found in the sample file match the ones
75+
# fetched above. This maps the arrays to a hash, making the creation of
76+
# each exclude and intersection list easier.
77+
my%gucs_in_file_hash =map {$_=> 1 }@gucs_in_file;
78+
my%all_params_hash =map {$_=> 1 }@all_params_array;
79+
my%not_in_sample_hash =map {$_=> 1 }@not_in_sample_array;
80+
81+
my@missing_from_file =grep(!$gucs_in_file_hash{$_},@all_params_array);
82+
is(scalar(@missing_from_file),
83+
0,"no parameters missing from postgresql.conf.sample");
84+
85+
my@missing_from_list =grep(!$all_params_hash{$_},@gucs_in_file);
86+
is(scalar(@missing_from_list), 0,"no parameters missing from guc.c");
87+
88+
my@sample_intersect =grep($not_in_sample_hash{$_},@gucs_in_file);
89+
is(scalar(@sample_intersect),
90+
0,"no parameters marked as NOT_IN_SAMPLE in postgresql.conf.sample");
91+
92+
# These would log some information only on errors.
93+
foreachmy$param (@missing_from_file)
94+
{
95+
print("found GUC$param in guc.c, missing from postgresql.conf.sample\n");
96+
}
97+
foreachmy$param (@missing_from_list)
98+
{
99+
print(
100+
"found GUC$param in postgresql.conf.sample, with incorrect info in guc.c\n"
101+
);
102+
}
103+
foreachmy$param (@sample_intersect)
104+
{
105+
print(
106+
"found GUC$param in postgresql.conf.sample, marked as NOT_IN_SAMPLE\n"
107+
);
108+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp