diff --git a/t/moxi_all.pl b/t/moxi_all.pl index 14e8c37c..eb400bf3 100755 --- a/t/moxi_all.pl +++ b/t/moxi_all.pl @@ -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"; @@ -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); +} diff --git a/t/moxi_mock.pl b/t/moxi_mock.pl index ef4f6545..335fbd10 100755 --- a/t/moxi_mock.pl +++ b/t/moxi_mock.pl @@ -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"; @@ -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) { @@ -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;