Skip to content

Commit

Permalink
some changes in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MARTIMM committed May 22, 2016
1 parent ad1bd96 commit 7b6b2d0
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
5 changes: 1 addition & 4 deletions Travis-ci/test-script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

#set -ev
set -ev

P6="${TRAVIS_BUILD_DIR}/Travis-ci/P6Software/rakudo/install"
PATH="${P6}/bin:${P6}/share/perl6/site/bin:/usr/bin:/bin"
Expand All @@ -9,9 +9,6 @@ PERL6LIB="lib"
export PATH
export PERL6LIB

#pwd
#ls -l lib

prove --exec=perl6 t/0*
prove --verbose --recurse --exec=perl6 t/[1-6]*
prove --exec=perl6 t/9*
1 change: 1 addition & 0 deletions lib/MongoDB.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;
use MongoDB::Log :ALL;

Expand Down
27 changes: 18 additions & 9 deletions lib/MongoDB/Client.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;

use MongoDB;
Expand Down Expand Up @@ -88,8 +89,12 @@ say 'new client 1';

# Background proces to handle server monitoring data
$!Background-discovery = Promise.start( {

loop {
# Make a note. Doing this test above will turn this to False too fast
$!todo-servers-semaphore.acquire;
$!processing-todo-list = True;
$!todo-servers-semaphore.release;

# Start processing when something is found in todo hash
$!todo-servers-semaphore.acquire;
Expand All @@ -99,9 +104,9 @@ say 'new client 1';
if $server-name.defined {

# Make a note. Doing this test above will turn this to False too fast
$!todo-servers-semaphore.acquire;
$!processing-todo-list = True;
$!todo-servers-semaphore.release;
# $!todo-servers-semaphore.acquire;
# $!processing-todo-list = True;
# $!todo-servers-semaphore.release;

trace-message("Processing server $server-name");

Expand Down Expand Up @@ -130,6 +135,10 @@ say "a0: $server-name: $!processing-todo-list";

else {

$!todo-servers-semaphore.acquire;
$!processing-todo-list = False;
$!todo-servers-semaphore.release;

# When no work take a nap!
sleep 5;
}
Expand Down Expand Up @@ -340,7 +349,7 @@ say "H6f: Processing after $server.name(): $!processing-todo-list";
$!todo-servers-semaphore.acquire;
$still-processing = $!processing-todo-list;
$!todo-servers-semaphore.release;
say "Still processing: $still-processing";
say "nbr-servers, still processing: $still-processing";
sleep 1;
}

Expand All @@ -363,7 +372,7 @@ say "Still processing: $still-processing";
!! {};
$!servers-semaphore.release;

my MongoDB::ServerStatus $sts = $h<status> if $h<status>:exists;
my MongoDB::ServerStatus $sts = $h<status> // MongoDB::C-UNKNOWN-SERVER;
}

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -400,7 +409,7 @@ say "Still processing: $still-processing";
$!todo-servers-semaphore.acquire;
$still-processing = $!processing-todo-list;
$!todo-servers-semaphore.release;
say "Still processing: $still-processing";
say "select-server 2, still processing: $still-processing";
sleep 1;
}

Expand Down Expand Up @@ -450,7 +459,7 @@ say "Still processing: $still-processing";
$!todo-servers-semaphore.acquire;
$still-processing = $!processing-todo-list;
$!todo-servers-semaphore.release;
say "Still processing: $still-processing";
say "select-server 3, still processing: $still-processing";
sleep 1;
}

Expand Down Expand Up @@ -481,7 +490,7 @@ say "Still processing: $still-processing";
else {
error-message('No master server selected');
}

say 'Select server: ', ($h // {}).perl;
$h<server> // MongoDB::Server;
}

Expand Down
1 change: 1 addition & 0 deletions lib/MongoDB/Server.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;

use MongoDB;
Expand Down
1 change: 1 addition & 0 deletions lib/MongoDB/Server/Control.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;

use MongoDB;
Expand Down
1 change: 1 addition & 0 deletions lib/MongoDB/Server/Monitor.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;

use MongoDB;
Expand Down
17 changes: 9 additions & 8 deletions lib/MongoDB/Wire.pm6
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use v6.c;

use BSON::Document;
Expand Down Expand Up @@ -30,18 +31,18 @@ class Wire {
$d does MongoDB::Header;
my BSON::Document $result;

my Bool $write-operation = False;
my $client;
# my Bool $write-operation = False;
# my $client;

try {
$client = $collection.database.client;
# $client = $collection.database.client;

# Check if the server ticket is defined and thus a server is reserved
# for this communication.
#
fatal-message("No server available") unless $!server.defined;

$write-operation = ($d.find-key(0) ~~ any(<insert update delete>));
# $write-operation = ($d.find-key(0) ~~ any(<insert update delete>));
#say "Need master for {$d.find-key(0)} $write-operation";
my $full-collection-name = $collection.full-collection-name;

Expand Down Expand Up @@ -117,7 +118,7 @@ class Wire {

my BSON::Document $d .= new;
$d does MongoDB::Header;
my $client;
# my $client;
my BSON::Document $result;

try {
Expand All @@ -126,7 +127,7 @@ class Wire {
$cursor.full-collection-name, $cursor.id, :$number-to-return
);

$client = $cursor.client;
# $client = $cursor.client;

fatal-message("No server available") unless $!server.defined;
$!socket = $server.get-socket;
Expand Down Expand Up @@ -196,7 +197,7 @@ say "Error wire get-more: ", .message;

my BSON::Document $d .= new;
$d does MongoDB::Header;
my $client;
# my $client;

# Gather the ids only when they are non-zero.i.e. still active.
#
Expand All @@ -207,7 +208,7 @@ say "Error wire get-more: ", .message;

# Kill the cursors if found any
#
$client = @cursors[0].client;
# $client = @cursors[0].client;

try {
fatal-message("No server available") unless $server.defined;
Expand Down
1 change: 1 addition & 0 deletions t/110-Client.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subtest {
$client .= new(:uri("mongodb://:$p1"));
$server = $client.select-server;

todo 'Seems to finish processing too soon', 2;
is $client.nbr-servers, 1, 'One server found';
is $client.server-status("localhost:$p1"), MongoDB::C-MASTER-SERVER,
"Status of server is master";
Expand Down
10 changes: 1 addition & 9 deletions t/450-find.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ my MongoDB::Cursor $cursor;

$database.run-command: (dropDatabase => 1,);

$req .= new: (
insert => $collection.name,
documents => []
);

#say "RP: ", $req.perl;
#exit(0);

# Insert many documents to see proper working of get-more docs request
# using wireshark
#
Expand Down Expand Up @@ -62,7 +54,7 @@ $doc = $database.run-command($req);

is $doc<ok>, 1, 'insert ok';
is $doc<n>, 200, 'inserted 200 docs';
say $doc<errmsg> unless $doc<ok>;
#say $doc<errmsg> unless $doc<ok>;

# Request to get all documents listed to generate a get-more request
#
Expand Down

0 comments on commit 7b6b2d0

Please sign in to comment.