Skip to content

Commit a6eb046

Browse files
committed
Do not pass default params to psql() in TAP tests
Make the intent of the code more clear by not passing default arguments to the psql() function. The unaligned format and tuples_only are defaults in the test helper.
1 parent 019256d commit a6eb046

12 files changed

Lines changed: 394 additions & 544 deletions

t/002_settings_pgsm_track_planning.pl

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,59 +63,50 @@
6363
PGSM::append_to_file($stdout);
6464

6565
# Test: total_plan_time is not 0
66-
($cmdret, $stdout, $stderr) = $node->psql(
67-
'postgres',
68-
'SELECT total_plan_time FROM pg_stat_monitor WHERE calls = 2;',
69-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
66+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
67+
'SELECT total_plan_time FROM pg_stat_monitor WHERE calls = 2;');
7068
trim($stdout);
7169
isnt($stdout, '0', "Compare: total_plan_time is not 0).");
7270

7371
# Test: min_plan_time is not 0
74-
($cmdret, $stdout, $stderr) = $node->psql(
75-
'postgres',
76-
'SELECT min_plan_time FROM pg_stat_monitor WHERE calls = 2;',
77-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
72+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
73+
'SELECT min_plan_time FROM pg_stat_monitor WHERE calls = 2;');
7874
trim($stdout);
7975
isnt($stdout, '0', "Compare: min_plan_time is not 0).");
8076

8177
# Test: max_plan_time is not 0
82-
($cmdret, $stdout, $stderr) = $node->psql(
83-
'postgres',
84-
'SELECT max_plan_time FROM pg_stat_monitor WHERE calls = 2;',
85-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
78+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
79+
'SELECT max_plan_time FROM pg_stat_monitor WHERE calls = 2;');
8680
trim($stdout);
8781
isnt($stdout, '0', "Compare: max_plan_time is not 0).");
8882

8983
# Test: mean_plan_time is not 0
90-
($cmdret, $stdout, $stderr) = $node->psql(
91-
'postgres',
92-
'SELECT mean_plan_time FROM pg_stat_monitor WHERE calls = 2;',
93-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
84+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
85+
'SELECT mean_plan_time FROM pg_stat_monitor WHERE calls = 2;');
9486
trim($stdout);
9587
isnt($stdout, '0', "Compare: mean_plan_time is not 0).");
9688

9789
# Test: stddev_plan_time is not 0
98-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT stddev_plan_time FROM pg_stat_monitor WHERE calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
90+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT stddev_plan_time FROM pg_stat_monitor WHERE calls = 2;');
9991
#trim($stdout);
10092
#isnt($stdout, '0', "Compare: stddev_plan_time is not 0).");
10193

10294
# Test: total_plan_time = min_plan_time + max_plan_time
103-
($cmdret, $stdout, $stderr) = $node->psql(
104-
'postgres',
105-
'SELECT round(total_plan_time::numeric, 3) = round(min_plan_time::numeric + max_plan_time::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;',
106-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
95+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
96+
'SELECT round(total_plan_time::numeric, 3) = round(min_plan_time::numeric + max_plan_time::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;'
97+
);
10798
trim($stdout);
10899
is($stdout, 't',
109100
"Compare: round(total_plan_time::numeric, 3) = round(min_plan_time::numeric + max_plan_time::numeric, 3)."
110101
);
111102

112103
# Test: mean_plan_time = total_plan_time/2
113-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(mean_plan_time::numeric, 3) = round((total_plan_time / 2)::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
104+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(mean_plan_time::numeric, 3) = round((total_plan_time / 2)::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;');
114105
#trim($stdout);
115106
#is($stdout,'t',"Test mean_plan_time: round(mean_plan_time::numeric, 3) = round((total_plan_time / 2)::numeric, 3).");
116107

117108
# Test: stddev_plan_time = mean_plan_time - min_plan_time
118-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(stddev_plan_time::numeric, 3) = round(mean_plan_time::numeric - min_plan_time::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
109+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(stddev_plan_time::numeric, 3) = round(mean_plan_time::numeric - min_plan_time::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;');
119110
#trim($stdout);
120111
#is($stdout,'t',"Compare mean_plan_time: round(stddev_plan_time::numeric, 3) = round(mean_plan_time::numeric - min_plan_time::numeric, 3).");
121112

@@ -162,42 +153,32 @@
162153
PGSM::append_to_file($stdout);
163154

164155
# Test: total_plan_time is 0
165-
($cmdret, $stdout, $stderr) = $node->psql(
166-
'postgres',
167-
'SELECT total_plan_time FROM pg_stat_monitor WHERE calls = 2;',
168-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
156+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
157+
'SELECT total_plan_time FROM pg_stat_monitor WHERE calls = 2;');
169158
trim($stdout);
170159
is($stdout, '0', "Compare: total_plan_time is 0).");
171160

172161
# Test: min_plan_time is 0
173-
($cmdret, $stdout, $stderr) = $node->psql(
174-
'postgres',
175-
'SELECT min_plan_time FROM pg_stat_monitor WHERE calls = 2;',
176-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
162+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
163+
'SELECT min_plan_time FROM pg_stat_monitor WHERE calls = 2;');
177164
trim($stdout);
178165
is($stdout, '0', "Compare: min_plan_time is 0).");
179166

180167
# Test: max_plan_time is 0
181-
($cmdret, $stdout, $stderr) = $node->psql(
182-
'postgres',
183-
'SELECT max_plan_time FROM pg_stat_monitor WHERE calls = 2;',
184-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
168+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
169+
'SELECT max_plan_time FROM pg_stat_monitor WHERE calls = 2;');
185170
trim($stdout);
186171
is($stdout, '0', "Compare: max_plan_time is 0).");
187172

188173
# Test: mean_plan_time is 0
189-
($cmdret, $stdout, $stderr) = $node->psql(
190-
'postgres',
191-
'SELECT mean_plan_time FROM pg_stat_monitor WHERE calls = 2;',
192-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
174+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
175+
'SELECT mean_plan_time FROM pg_stat_monitor WHERE calls = 2;');
193176
trim($stdout);
194177
is($stdout, '0', "Compare: mean_plan_time is 0).");
195178

196179
# Test: stddev_plan_time is 0
197-
($cmdret, $stdout, $stderr) = $node->psql(
198-
'postgres',
199-
'SELECT stddev_plan_time FROM pg_stat_monitor WHERE calls = 2;',
200-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
180+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
181+
'SELECT stddev_plan_time FROM pg_stat_monitor WHERE calls = 2;');
201182
trim($stdout);
202183
is($stdout, '0', "Compare: stddev_plan_time is 0).");
203184

t/005_settings_pgsm_enable_query_plan.pl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@
8585
PGSM::append_to_file($stdout);
8686

8787
# Test: planid is not 0 or empty
88-
($cmdret, $stdout, $stderr) = $node->psql(
89-
'postgres',
90-
'SELECT planid FROM pg_stat_monitor WHERE calls = 2;',
91-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
88+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
89+
'SELECT planid FROM pg_stat_monitor WHERE calls = 2;');
9290
trim($stdout);
9391
isnt($stdout, '', "Test: planid should not be empty");
9492
ok(length($stdout) > 0, 'Length of planid is > 0');
@@ -155,10 +153,8 @@
155153
PGSM::append_to_file($stdout);
156154

157155
# Test: planid is empty
158-
($cmdret, $stdout, $stderr) = $node->psql(
159-
'postgres',
160-
'SELECT planid FROM pg_stat_monitor WHERE calls = 2;',
161-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
156+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
157+
'SELECT planid FROM pg_stat_monitor WHERE calls = 2;');
162158
trim($stdout);
163159
is($stdout, '', "Test: planid should be empty");
164160
is(length($stdout), 0, 'Length of planid is 0');

t/017_execution_stats.pl

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,59 +67,50 @@
6767
PGSM::append_to_file($stdout);
6868

6969
# Test: ${col_total_time} is not 0
70-
($cmdret, $stdout, $stderr) = $node->psql(
71-
'postgres',
72-
"SELECT ${col_total_time} FROM pg_stat_monitor WHERE calls = 2;",
73-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
70+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
71+
"SELECT ${col_total_time} FROM pg_stat_monitor WHERE calls = 2;");
7472
trim($stdout);
7573
isnt($stdout, '0', "Compare: ${col_total_time} is not 0).");
7674

7775
# Test: ${col_min_time} is not 0
78-
($cmdret, $stdout, $stderr) = $node->psql(
79-
'postgres',
80-
"SELECT ${col_min_time} FROM pg_stat_monitor WHERE calls = 2;",
81-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
76+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
77+
"SELECT ${col_min_time} FROM pg_stat_monitor WHERE calls = 2;");
8278
trim($stdout);
8379
isnt($stdout, '0', "Compare: ${col_min_time} is not 0).");
8480

8581
# Test: ${col_max_time} is not 0
86-
($cmdret, $stdout, $stderr) = $node->psql(
87-
'postgres',
88-
"SELECT ${col_max_time} FROM pg_stat_monitor WHERE calls = 2;",
89-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
82+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
83+
"SELECT ${col_max_time} FROM pg_stat_monitor WHERE calls = 2;");
9084
trim($stdout);
9185
isnt($stdout, '0', "Compare: ${col_max_time} is not 0).");
9286

9387
# Test: ${col_mean_time} is not 0
94-
($cmdret, $stdout, $stderr) = $node->psql(
95-
'postgres',
96-
"SELECT ${col_mean_time} FROM pg_stat_monitor WHERE calls = 2;",
97-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
88+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
89+
"SELECT ${col_mean_time} FROM pg_stat_monitor WHERE calls = 2;");
9890
trim($stdout);
9991
isnt($stdout, '0', "Compare: ${col_mean_time} is not 0).");
10092

10193
# Test: ${col_stddev_time} is not 0
102-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT ${col_stddev_time} FROM pg_stat_monitor WHERE calls = 2;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
94+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT ${col_stddev_time} FROM pg_stat_monitor WHERE calls = 2;");
10395
#trim($stdout);
10496
#isnt($stdout, '0', "Test: ${col_stddev_time} should not be 0).");
10597

10698
# Test: ${col_total_time} = ${col_min_time} + ${col_max_time}
107-
($cmdret, $stdout, $stderr) = $node->psql(
108-
'postgres',
109-
"SELECT (round(${col_total_time}::numeric, 3) = round(${col_min_time}::numeric + ${col_max_time}::numeric, 3)) FROM pg_stat_monitor WHERE calls = 2;",
110-
extra_params => [ '-Pformat=unaligned', '-Ptuples_only=on' ]);
99+
($cmdret, $stdout, $stderr) = $node->psql('postgres',
100+
"SELECT (round(${col_total_time}::numeric, 3) = round(${col_min_time}::numeric + ${col_max_time}::numeric, 3)) FROM pg_stat_monitor WHERE calls = 2;"
101+
);
111102
trim($stdout);
112103
is($stdout, 't',
113104
"Compare: (round(${col_total_time}::numeric, 3) = round(${col_min_time}::numeric + ${col_max_time}::numeric, 3))."
114105
);
115106

116107
# Test: ${col_mean_time} = ${col_total_time}/2
117-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT (round(${col_mean_time}::numeric, 3) = round((${col_total_time} / 2)::numeric, 3)) FROM pg_stat_monitor WHERE calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
108+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT (round(${col_mean_time}::numeric, 3) = round((${col_total_time} / 2)::numeric, 3)) FROM pg_stat_monitor WHERE calls = 2;');
118109
#trim($stdout);
119110
#is($stdout,'t',"Compare ${col_mean_time}: round(${col_mean_time}::numeric, 3) = round((${col_total_time} / 2)::numeric, 3).");
120111

121112
# Test: ${col_stddev_time} = ${col_mean_time} - ${col_min_time}
122-
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(${col_stddev_time}::numeric, 3) = round(${col_mean_time}::numeric - ${col_min_time}::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
113+
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT round(${col_stddev_time}::numeric, 3) = round(${col_mean_time}::numeric - ${col_min_time}::numeric, 3) FROM pg_stat_monitor WHERE calls = 2;');
123114
#trim($stdout);
124115
#is($stdout,'t',"Compare ${col_mean_time}: round(${col_stddev_time}::numeric, 3) = round(${col_mean_time}::numeric - ${col_min_time}::numeric, 3)).");
125116

t/018_column_names.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
($cmdret, $stdout, $stderr) = $node->psql(
111111
'postgres',
112112
"SELECT column_name FROM information_schema.columns WHERE table_name = 'pg_stat_monitor' ORDER BY column_name;",
113-
extra_params => [ '-A', '-R,', '-Ptuples_only=on' ]);
113+
extra_params => ['-R,']);
114114
is($cmdret, 0,
115115
"Get columns names in PGSM installation for PG version $PGSM::PG_MAJOR_VERSION"
116116
);

0 commit comments

Comments
 (0)