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

Commit49b6f4a

Browse files
committed
backport: Extend background_psql() to be able to start asynchronously
This is a backport ofba08edb. Originally it was only applied to master,but I (Andres) am planning to fix a few bugs in BackgroundPsql, which would besomewhat harder with the behavioural differences across branches. It's alsogenerally good for test infrastructure to behave similarly across branches, toavoid pain during backpatching.Discussion:https://postgr.es/m/ilcctzb5ju2gulvnadjmhgatnkxsdpac652byb2u3d3wqziyvx@fbuqcglker46Michael's original commit message:This commit extends the constructor routine of BackgroundPsql.pm with anew "wait" parameter. If set to 0, the routine returns without waitingfor psql to start, ready to consume input.background_psql() in Cluster.pm gains the same "wait" parameter. Thedefault behavior is still to wait for psql to start. It becomes nowpossible to not wait, giving to TAP scripts the possibility to performactions between a BackgroundPsql startup and its wait_connect() call.Author: Jacob ChampionDiscussion:https://postgr.es/m/CAOYmi+=60deN20WDyCoHCiecgivJxr=98s7s7-C8SkXwrCfHXg@mail.gmail.com
1 parent31a242e commit49b6f4a

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

‎src/test/perl/PostgreSQL/Test/BackgroundPsql.pm

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,23 @@ use Test::More;
6868
6969
=over
7070
71-
=itemPostgreSQL::Test::BackgroundPsql->new(interactive, @psql_params, timeout)
71+
=itemPostgreSQL::Test::BackgroundPsql->new(interactive, @psql_params, timeout, wait)
7272
7373
Builds a new object of classC<PostgreSQL::Test::BackgroundPsql> for either
7474
an interactive or background session and starts it. IfC<interactive> is
7575
true then a PTY will be attached.C<psql_params> should contain the full
7676
command to run psql with all desired parameters and a complete connection
7777
string. ForC<interactive> sessions, IO::Pty is required.
7878
79+
This routine will not return until psql has started up and is ready to
80+
consume input. SetB<wait> to 0 to return immediately instead.
81+
7982
=cut
8083

8184
subnew
8285
{
8386
my$class =shift;
84-
my ($interactive,$psql_params,$timeout) =@_;
87+
my ($interactive,$psql_params,$timeout,$wait) =@_;
8588
my$psql = {
8689
'stdin'=>'',
8790
'stdout'=>'',
@@ -119,14 +122,25 @@ sub new
119122

120123
my$self =bless$psql,$class;
121124

122-
$self->_wait_connect();
125+
$wait = 1unlessdefined($wait);
126+
if ($wait)
127+
{
128+
$self->wait_connect();
129+
}
123130

124131
return$self;
125132
}
126133

127-
# Internal routine for awaiting psql starting up and being ready to consume
128-
# input.
129-
sub_wait_connect
134+
=pod
135+
136+
=item$session->wait_connect
137+
138+
Returns once psql has started up and is ready to consume input. This is called
139+
automatically for clients unless requested otherwise in the constructor.
140+
141+
=cut
142+
143+
subwait_connect
130144
{
131145
my ($self) =@_;
132146

@@ -187,7 +201,7 @@ sub reconnect_and_clear
187201
$self->{stdin} ='';
188202
$self->{stdout} ='';
189203

190-
$self->_wait_connect();
204+
$self->wait_connect();
191205
}
192206

193207
=pod

‎src/test/perl/PostgreSQL/Test/Cluster.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,12 @@ connection.
21912191
21922192
If given, it must be an array reference containing additional parameters toB<psql>.
21932193
2194+
=itemwait => 1
2195+
2196+
By default, this method will not return until connection has completed (or
2197+
failed). SetB<wait> to 0 to return immediately instead. (Clients can call the
2198+
session'sC<wait_connect> method manually when needed.)
2199+
21942200
=back
21952201
21962202
=cut
@@ -2214,13 +2220,15 @@ sub background_psql
22142220
'-');
22152221

22162222
$params{on_error_stop} = 1unlessdefined$params{on_error_stop};
2223+
$params{wait} = 1unlessdefined$params{wait};
22172224
$timeout =$params{timeout}ifdefined$params{timeout};
22182225

22192226
push@psql_params,'-v','ON_ERROR_STOP=1'if$params{on_error_stop};
22202227
push@psql_params, @{$params{extra_params} }
22212228
ifdefined$params{extra_params};
22222229

2223-
return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params,$timeout);
2230+
return PostgreSQL::Test::BackgroundPsql->new(0, \@psql_params,$timeout,
2231+
$params{wait});
22242232
}
22252233

22262234
=pod

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp