Skip to content

Commit

Permalink
hooked up more tests to 'make test'
Browse files Browse the repository at this point in the history
moxi_mock.pl script is now reusable, at the cost of some (perl
inspired) readability.  It's now invoked to also run the mock auth,
multitenancy, and multitenancy_default tests scripts (combinations of
spawning a fake rest/http server, a moxi with the right params, and
the right python test scripts to drive it).

Change-Id: If7c16c9709ab59320d804909f578c7f9966a7a29
Reviewed-on: http://review.northscale.com/2644
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information
steveyen committed Sep 23, 2010
1 parent 65fdc5a commit fa9b090
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
46 changes: 44 additions & 2 deletions t/moxi_all.pl
Expand Up @@ -11,6 +11,9 @@
croak("moxi binary not executable\n") unless -x _;

sub go {
if ($ARGV[0] eq 'mock_only') {
return;
}
my ($topology, $protocol) = @_;
print "------------------------------------\n";
print "testing $topology $protocol\n";
Expand All @@ -33,10 +36,49 @@ sub go {
go('simple', 'binary');
go('fanout', 'binary');

print "------------------------------------\n";
print "------------------------------------ ascii\n";

my $res = system("./t/moxi_mock.pl ascii");
if ($res != 0) {
print "exit: $res\n";
exit($res);
}

print "------------------------------------ auth\n";

my $res = system("./t/moxi_mock.pl moxi_mock_auth binary \"\"" .
" url=http://127.0.0.1:4567/pools/default/buckets/default" .
" usr=TheUser,pwd=ThePassword,port_listen=11333," .
" ./t/rest_mock.rb");
if ($res != 0) {
print "exit: $res\n";
exit($res);
}

sleep(1);

exit $res;
print "------------------------------------ multitenancy\n";

my $res = system("./t/moxi_mock.pl moxi_multitenancy binary \"\"" .
" url=http://127.0.0.1:4567/pools/default/buckets/default" .
" default_bucket_name=,port_listen=11333," .
" \"./t/rest_mock.rb ./t/moxi_multitenancy_rest.cfg\"");
if ($res != 0) {
print "exit: $res\n";
exit($res);
}

sleep(1);

print "------------------------------------ multitenancy_default\n";

my $res = system("./t/moxi_mock.pl moxi_multitenancy_default binary \"\"" .
" url=http://127.0.0.1:4567/pools/default/buckets/default" .
" default_bucket_name=default,port_listen=11333," .
" \"./t/rest_mock.rb ./t/moxi_multitenancy_rest_default.cfg\"");
if ($res != 0) {
print "exit: $res\n";
exit($res);
}


57 changes: 52 additions & 5 deletions t/moxi_mock.pl
Expand Up @@ -4,15 +4,30 @@
#
# ./t/moxi_mock.pl [upstream_protocol] [downstream_protocol] [test_name]
#
# An upstream_protocol/downstream_protocol is ascii or binary.
#
# Parameters are optional, so these examples work, and default to ascii...
#
# ./t/moxi_mock.pl
# ./t/moxi_mock.pl ascii
# ./t/moxi_mock.pl ascii ascii TestProxyAscii.testBasicQuit
#
# Alternative command-line...
#
# ./t/moxi_mock.pl [mock_test] [downstream_protocol] [test_name] \
# [moxi-z-param] [moxi-Z-param] [rest/http-server-params]
#
# ./t/moxi_mock.pl moxi_mock_auth binary "" \
# url=http://127.0.0.1:4567/pools/default/buckets/default \
# usr=TheUser,pwd=ThePassword,port_listen=11333, \
# ./t/rest_mock.rb
#
my $upstream_protocol = $ARGV[0] || 'ascii';
my $downstream_protocol = $ARGV[1] || 'ascii';
my $test_name = $ARGV[2] || '';
my $little_z = $ARGV[3] || './t/moxi_mock.cfg';
my $big_Z = $ARGV[4] || '';
my $restargs = $ARGV[5] || '...NONE...';

print "moxi_mock.pl: " . $upstream_protocol . " " . $downstream_protocol . " " . $test_name + "\n";

Expand All @@ -21,14 +36,33 @@
croak("moxi binary doesn't exist. Haven't run 'make' ?\n") unless -e $exe;
croak("moxi binary not executable\n") unless -x _;

# Fork rest/http server if necessary.
#
my $restpid = -1;
if ($restargs ne '...NONE...') {
print($restargs . "\n");
$restpid = fork();
unless ($restpid) {
setpgrp();
exec "ruby $restargs";
exit;
}
setpgrp($childpid, $childpid);
sleep(1);
}

# Fork moxi for moxi-specific testing.
#
my $childargs =
" -z ./t/moxi_mock.cfg".
" -p 0 -U 0 -v -t 1 -Z \"downstream_max=1,downstream_protocol=" . $downstream_protocol . "\"";
" -z ". $little_z .
" -p 0 -U 0 -v -t 1".
" -Z \"". $big_Z ."downstream_max=1,downstream_protocol=" . $downstream_protocol . "\"";
if ($< == 0) {
$childargs .= " -u root";
}

print($childargs . "\n");

my $childpid = fork();

unless ($childpid) {
Expand All @@ -37,12 +71,25 @@
exit; # never gets here.
}
setpgrp($childpid, $childpid);
sleep(1);

my $u = substr($upstream_protocol, 0, 1); # This is 'a' or 'b'.
my $d = substr($downstream_protocol, 0, 1); # This is 'a' or 'b'.
my $result = -1;

my $result = system("python ./t/moxi_mock_" . $u . "2" . $d . ".py " . $test_name);
if ($upstream_protocol ne 'ascii' &&
$upstream_protocol ne 'binary') {
$result = system("python ./t/" . $ARGV[0] . ".py " . $test_name);
} else {
my $u = substr($upstream_protocol, 0, 1); # This is 'a' or 'b'.
my $d = substr($downstream_protocol, 0, 1); # This is 'a' or 'b'.

$result = system("python ./t/moxi_mock_" . $u . "2" . $d . ".py " . $test_name);
}

kill 2, -$childpid;

if ($restpid >= 0) {
kill 2, -$restpid;
sleep(1);
}

exit $result;

0 comments on commit fa9b090

Please sign in to comment.