You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2016/09/30 15:45:19 UTC
[2/2] lucy git commit: Try several ports in remote searcher tests
Try several ports in remote searcher tests
Fixes LUCY-312.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0959ad9d
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0959ad9d
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0959ad9d
Branch: refs/heads/master
Commit: 0959ad9d3ffa474396059268e431fa43daa9a1c4
Parents: 26d3c77
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Fri Sep 30 17:16:58 2016 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Sep 30 17:32:56 2016 +0200
----------------------------------------------------------------------
perl/lib/LucyX/Remote/SearchServer.pm | 6 +++++
perl/t/510-remote_search.t | 33 ++++++++++++++++-------
perl/t/550-cluster_searcher.t | 42 +++++++++++++++++++++---------
3 files changed, 59 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/0959ad9d/perl/lib/LucyX/Remote/SearchServer.pm
----------------------------------------------------------------------
diff --git a/perl/lib/LucyX/Remote/SearchServer.pm b/perl/lib/LucyX/Remote/SearchServer.pm
index 6950c24..dc3f0aa 100644
--- a/perl/lib/LucyX/Remote/SearchServer.pm
+++ b/perl/lib/LucyX/Remote/SearchServer.pm
@@ -67,6 +67,12 @@ sub serve {
Reuse => 1,
);
confess("No socket: $!") unless $main_sock;
+ $self->serve_sock($main_sock);
+}
+
+sub serve_sock {
+ my ( $self, $main_sock ) = @_;
+
my $read_set = IO::Select->new($main_sock);
while ( my @ready = $read_set->can_read ) {
http://git-wip-us.apache.org/repos/asf/lucy/blob/0959ad9d/perl/t/510-remote_search.t
----------------------------------------------------------------------
diff --git a/perl/t/510-remote_search.t b/perl/t/510-remote_search.t
index 574e9ab..a71763d 100644
--- a/perl/t/510-remote_search.t
+++ b/perl/t/510-remote_search.t
@@ -20,7 +20,9 @@ use Test::More;
use Time::HiRes qw( sleep );
use IO::Socket::INET;
-my $PORT_NUM = 7890;
+my $min_port = 7900;
+my $max_port = 7919;
+
BEGIN {
if ( $^O =~ /(mswin|cygwin)/i ) {
plan( 'skip_all', "fork on Windows not supported by Lucy" );
@@ -50,13 +52,22 @@ use Lucy::Test;
use LucyX::Remote::SearchServer;
use LucyX::Remote::SearchClient;
-my $kid;
-$kid = fork;
-if ($kid) {
- sleep .25; # allow time for the server to set up the socket
- die "Failed fork: $!" unless defined $kid;
+my ( $port, $sock );
+for ( $port = $min_port; $port <= $max_port; $port++ ) {
+ $sock = IO::Socket::INET->new(
+ LocalPort => $port,
+ Proto => 'tcp',
+ Listen => SOMAXCONN,
+ Reuse => 1,
+ );
+ last if $sock;
}
-else {
+die "No socket: $!" unless $sock;
+
+my $kid = fork;
+die "Failed fork: $!" unless defined $kid;
+
+if ( $kid == 0 ) {
my $folder = Lucy::Store::RAMFolder->new;
my $indexer = Lucy::Index::Indexer->new(
index => $folder,
@@ -73,12 +84,14 @@ else {
my $server = LucyX::Remote::SearchServer->new(
searcher => $searcher,
);
- $server->serve( port => $PORT_NUM );
+ $server->serve_sock($sock);
exit(0);
}
+$sock->close;
+
my $test_client_sock = IO::Socket::INET->new(
- PeerAddr => "localhost:$PORT_NUM",
+ PeerAddr => "localhost:$port",
Proto => 'tcp',
);
if ($test_client_sock) {
@@ -91,7 +104,7 @@ else {
my $searchclient = LucyX::Remote::SearchClient->new(
schema => SortSchema->new,
- peer_address => "localhost:$PORT_NUM",
+ peer_address => "localhost:$port",
);
is( $searchclient->doc_freq( field => 'content', term => 'x' ),
http://git-wip-us.apache.org/repos/asf/lucy/blob/0959ad9d/perl/t/550-cluster_searcher.t
----------------------------------------------------------------------
diff --git a/perl/t/550-cluster_searcher.t b/perl/t/550-cluster_searcher.t
index bc19e0c..a96cbbb 100644
--- a/perl/t/550-cluster_searcher.t
+++ b/perl/t/550-cluster_searcher.t
@@ -20,7 +20,10 @@ use Test::More;
use Time::HiRes qw( sleep );
use IO::Socket::INET;
-my @ports = 7890 .. 7895;
+my $num_servers = 6;
+my $min_port = 7000;
+my $max_port = 7099;
+
BEGIN {
if ( $^O =~ /(mswin|cygwin)/i ) {
plan( 'skip_all', "fork on Windows not supported by Lucy" );
@@ -55,15 +58,29 @@ use Lucy::Test;
use LucyX::Remote::SearchServer;
use LucyX::Remote::ClusterSearcher;
+my @ports;
+my $port = $min_port;
my @kids;
my $number = 7;
-for my $port (@ports) {
- my $kid = fork;
- if ($kid) {
- die "Failed fork: $!" unless defined $kid;
- push @kids, $kid;
+for ( my $i = 0; $i < $num_servers; $i++ ) {
+ my $sock;
+ while ( $port <= $max_port ) {
+ $sock = IO::Socket::INET->new(
+ LocalPort => $port,
+ Proto => 'tcp',
+ Listen => SOMAXCONN,
+ Reuse => 1,
+ );
+ last if $sock;
+ $port++;
}
- else {
+ die "No socket: $!" unless $sock;
+ push @ports, $port;
+
+ my $kid = fork;
+ die "Failed fork: $!" unless defined $kid;
+
+ if ( $kid == 0 ) {
my $folder = Lucy::Store::RAMFolder->new;
my $indexer = Lucy::Index::Indexer->new(
index => $folder,
@@ -85,13 +102,14 @@ for my $port (@ports) {
my $server = LucyX::Remote::SearchServer->new(
searcher => $searcher,
);
- $server->serve( port => $port );
+ $server->serve_sock($sock);
exit(0);
}
-}
-# Allow time for the servers to set up their sockets.
-sleep .5;
+ $sock->close;
+ push @kids, $kid;
+ $port++;
+}
my $test_client_sock = IO::Socket::INET->new(
PeerAddr => "localhost:$ports[0]",
@@ -130,7 +148,7 @@ my $cluster_searcher = LucyX::Remote::ClusterSearcher->new(
);
$hits = $cluster_searcher->hits( query => 'b' );
-is( $hits->total_hits, scalar @ports, "matched hits across multiple shards" );
+is( $hits->total_hits, $num_servers, "matched hits across multiple shards" );
my $highlighter = Lucy::Highlight::Highlighter->new(
searcher => $cluster_searcher,