Skip to content

Commit d5fd786

Browse files
committed
Backport BackgroundPsql perl test module
Backport the new BackgroundPsql modules and the constructor functions, background_psql() and interactive_psql, to all supported branches. That makes it easier to backpatch tests that use it. BackgroundPsql was introduced in version 16. On version 16, this commit backports just the new timeout argument from master (commit 334f512). On older branches, the whole facility. This includes the change to `use warnings FATAL => 'all'`, which we haven't otherwise backported, but it seems good to keep the file identical across branches. Discussion: https://www.postgresql.org/message-id/b7c64f20-ea01-4f15-9088-0cd6832af149@iki.fi
1 parent 76fda61 commit d5fd786

File tree

8 files changed

+407
-260
lines changed

8 files changed

+407
-260
lines changed

contrib/amcheck/t/003_cic_2pc.pl

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,63 +36,46 @@
3636
# statements.
3737
#
3838

39-
my $main_in = '';
40-
my $main_out = '';
41-
my $main_timer = IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
42-
43-
my $main_h =
44-
$node->background_psql('postgres', \$main_in, \$main_out,
45-
$main_timer, on_error_stop => 1);
46-
$main_in .= q(
39+
my $main_h = $node->background_psql('postgres');
40+
41+
$main_h->query_safe(q(
4742
BEGIN;
4843
INSERT INTO tbl VALUES(0);
49-
\echo syncpoint1
50-
);
51-
pump $main_h until $main_out =~ /syncpoint1/ || $main_timer->is_expired;
52-
53-
my $cic_in = '';
54-
my $cic_out = '';
55-
my $cic_timer = IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
56-
my $cic_h =
57-
$node->background_psql('postgres', \$cic_in, \$cic_out,
58-
$cic_timer, on_error_stop => 1);
59-
$cic_in .= q(
44+
));
45+
46+
my $cic_h = $node->background_psql('postgres');
47+
48+
$cic_h->query_until(qr/start/, q(
6049
\echo start
6150
CREATE INDEX CONCURRENTLY idx ON tbl(i);
62-
);
63-
pump $cic_h until $cic_out =~ /start/ || $cic_timer->is_expired;
51+
));
6452

65-
$main_in .= q(
53+
$main_h->query_safe(q(
6654
PREPARE TRANSACTION 'a';
67-
);
55+
));
6856

69-
$main_in .= q(
57+
$main_h->query_safe(q(
7058
BEGIN;
7159
INSERT INTO tbl VALUES(0);
72-
\echo syncpoint2
73-
);
74-
pump $main_h until $main_out =~ /syncpoint2/ || $main_timer->is_expired;
60+
));
7561

7662
$node->safe_psql('postgres', q(COMMIT PREPARED 'a';));
7763

78-
$main_in .= q(
64+
$main_h->query_safe(q(
7965
PREPARE TRANSACTION 'b';
8066
BEGIN;
8167
INSERT INTO tbl VALUES(0);
82-
\echo syncpoint3
83-
);
84-
pump $main_h until $main_out =~ /syncpoint3/ || $main_timer->is_expired;
68+
));
8569

8670
$node->safe_psql('postgres', q(COMMIT PREPARED 'b';));
8771

88-
$main_in .= q(
72+
$main_h->query_safe(q(
8973
PREPARE TRANSACTION 'c';
9074
COMMIT PREPARED 'c';
91-
);
92-
$main_h->pump_nb;
75+
));
9376

94-
$main_h->finish;
95-
$cic_h->finish;
77+
$main_h->quit;
78+
$cic_h->quit;
9679

9780
$result = $node->psql('postgres', q(SELECT bt_index_check('idx',true)));
9881
is($result, '0', 'bt_index_check after overlapping 2PC');
@@ -113,22 +96,15 @@
11396
));
11497
$node->restart;
11598

116-
my $reindex_in = '';
117-
my $reindex_out = '';
118-
my $reindex_timer =
119-
IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
120-
my $reindex_h =
121-
$node->background_psql('postgres', \$reindex_in, \$reindex_out,
122-
$reindex_timer, on_error_stop => 1);
123-
$reindex_in .= q(
99+
my $reindex_h = $node->background_psql('postgres');
100+
$reindex_h->query_until(qr/start/, q(
124101
\echo start
125102
DROP INDEX CONCURRENTLY idx;
126103
CREATE INDEX CONCURRENTLY idx ON tbl(i);
127-
);
128-
pump $reindex_h until $reindex_out =~ /start/ || $reindex_timer->is_expired;
104+
));
129105

130106
$node->safe_psql('postgres', "COMMIT PREPARED 'spans_restart'");
131-
$reindex_h->finish;
107+
$reindex_h->quit;
132108
$result = $node->psql('postgres', q(SELECT bt_index_check('idx',true)));
133109
is($result, '0', 'bt_index_check after 2PC and restart');
134110

src/bin/psql/t/010_tab_completion.pl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PostgreSQL::Test::Cluster;
88
use PostgreSQL::Test::Utils;
99
use Test::More;
10-
use IPC::Run qw(pump finish timer);
1110
use Data::Dumper;
1211

1312
# Do nothing unless Makefile has told us that the build is --with-readline.
@@ -91,14 +90,7 @@
9190
close $FH;
9291

9392
# fire up an interactive psql session
94-
my $in = '';
95-
my $out = '';
96-
97-
my $timer = timer($PostgreSQL::Test::Utils::timeout_default);
98-
99-
my $h = $node->interactive_psql('postgres', \$in, \$out, $timer);
100-
101-
like($out, qr/psql/, "print startup banner");
93+
my $h = $node->interactive_psql('postgres');
10294

10395
# Simple test case: type something and see if psql responds as expected
10496
sub check_completion
@@ -108,15 +100,12 @@ sub check_completion
108100
# report test failures from caller location
109101
local $Test::Builder::Level = $Test::Builder::Level + 1;
110102

111-
# reset output collector
112-
$out = "";
113103
# restart per-command timer
114-
$timer->start($PostgreSQL::Test::Utils::timeout_default);
115-
# send the data to be sent
116-
$in .= $send;
117-
# wait ...
118-
pump $h until ($out =~ $pattern || $timer->is_expired);
119-
my $okay = ($out =~ $pattern && !$timer->is_expired);
104+
$h->{timeout}->start($PostgreSQL::Test::Utils::timeout_default);
105+
106+
# send the data to be sent and wait for its result
107+
my $out = $h->query_until($pattern, $send);
108+
my $okay = ($out =~ $pattern && !$h->{timeout}->is_expired);
120109
ok($okay, $annotation);
121110
# for debugging, log actual output if it didn't match
122111
local $Data::Dumper::Terse = 1;
@@ -442,10 +431,7 @@ sub clear_line
442431
clear_query();
443432

444433
# send psql an explicit \q to shut it down, else pty won't close properly
445-
$timer->start($PostgreSQL::Test::Utils::timeout_default);
446-
$in .= "\\q\n";
447-
finish $h or die "psql returned $?";
448-
$timer->reset;
434+
$h->quit or die "psql returned $?";
449435

450436
# done
451437
$node->stop;

0 commit comments

Comments
 (0)