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

Commit3b7bbee

Browse files
committed
Make PostgresNode easily subclassable
This module becomes much more useful if we allow it to be used as baseclass for external projects. To achieve this, change the exportedget_new_node function into a class method instead, and use the standardPerl idiom of accepting the class as first argument. This method worksas expected for subclasses. The standalone function is kept forbackwards compatibility, though it could be removed in pg11.Author: Chap Flackman, based on an earlier patch from Craig RingerDiscussion:https://postgr.es/m/CAMsr+YF8kO+4+K-_U4PtN==2FndJ+5Bn6A19XHhMiBykEwv0wA@mail.gmail.com
1 parent51865a0 commit3b7bbee

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

‎src/test/perl/PostgresNode.pm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PostgresNode - class representing PostgreSQL server instance
99
1010
use PostgresNode;
1111
12-
my $node = get_new_node('mynode');
12+
my $node =PostgresNode->get_new_node('mynode');
1313
1414
# Create a data directory with initdb
1515
$node->init();
@@ -845,20 +845,24 @@ sub _update_pid
845845

846846
=pod
847847
848-
=itemget_new_node(node_name)
848+
=itemPostgresNode->get_new_node(node_name)
849849
850-
Build a new PostgresNode object, assigning a free port number. Standalone
851-
function that's automatically imported.
850+
Build a new object of classC<PostgresNode> (or of a subclass, if you have
851+
one), assigning a free port number. Remembers the node, to prevent its port
852+
number from being reused for another node, and to ensure that it gets
853+
shut down when the test script exits.
852854
853-
Remembers the node, to prevent its port number from being reused for another
854-
node, and to ensure that it gets shut down when the test script exits.
855+
You should generally use this instead ofC<PostgresNode::new(...)>.
855856
856-
You should generally use this instead of PostgresNode::new(...).
857+
For backwards compatibility, it is also exported as a standalone function,
858+
which can only create objects of classC<PostgresNode>.
857859
858860
=cut
859861

860862
subget_new_node
861863
{
864+
my$class ='PostgresNode';
865+
$class =shiftif 1 <scalar@_;
862866
my$name =shift;
863867
my$found = 0;
864868
my$port =$last_port_assigned;
@@ -903,7 +907,7 @@ sub get_new_node
903907
print"# Found free port$port\n";
904908

905909
# Lock port number found by creating a new node
906-
my$node = new PostgresNode($name,$test_pghost,$port);
910+
my$node =$class->new($name,$test_pghost,$port);
907911

908912
# Add node to list of nodes
909913
push(@all_nodes,$node);

‎src/test/perl/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Each test script should begin with:
4242
then it will generally need to set up one or more nodes, run commands
4343
against them and evaluate the results. For example:
4444

45-
my $node = get_new_node('master');
45+
my $node =PostgresNode->get_new_node('master');
4646
$node->init;
4747
$node->start;
4848

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp