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

Commit54dacc7

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 parent9915de6 commit54dacc7

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();
@@ -855,20 +855,24 @@ sub _update_pid
855855

856856
=pod
857857
858-
=itemget_new_node(node_name)
858+
=itemPostgresNode->get_new_node(node_name)
859859
860-
Build a new PostgresNode object, assigning a free port number. Standalone
861-
function that's automatically imported.
860+
Build a new object of classC<PostgresNode> (or of a subclass, if you have
861+
one), assigning a free port number. Remembers the node, to prevent its port
862+
number from being reused for another node, and to ensure that it gets
863+
shut down when the test script exits.
862864
863-
Remembers the node, to prevent its port number from being reused for another
864-
node, and to ensure that it gets shut down when the test script exits.
865+
You should generally use this instead ofC<PostgresNode::new(...)>.
865866
866-
You should generally use this instead of PostgresNode::new(...).
867+
For backwards compatibility, it is also exported as a standalone function,
868+
which can only create objects of classC<PostgresNode>.
867869
868870
=cut
869871

870872
subget_new_node
871873
{
874+
my$class ='PostgresNode';
875+
$class =shiftif 1 <scalar@_;
872876
my$name =shift;
873877
my$found = 0;
874878
my$port =$last_port_assigned;
@@ -913,7 +917,7 @@ sub get_new_node
913917
print"# Found free port$port\n";
914918

915919
# Lock port number found by creating a new node
916-
my$node = new PostgresNode($name,$test_pghost,$port);
920+
my$node =$class->new($name,$test_pghost,$port);
917921

918922
# Add node to list of nodes
919923
push(@all_nodes,$node);

‎src/test/perl/README

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

51-
my $node = get_new_node('master');
51+
my $node =PostgresNode->get_new_node('master');
5252
$node->init;
5353
$node->start;
5454

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp