summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/cluster_authentication_soak.cpp
diff options
context:
space:
mode:
authorMichael Goulish <mgoulish@apache.org>2010-05-24 18:25:46 +0000
committerMichael Goulish <mgoulish@apache.org>2010-05-24 18:25:46 +0000
commitba91599c45eeb8f3578cd34092302b2394b9ea69 (patch)
treeeca1f864eaa85a847ee10dab38554695f2aa5fc0 /qpid/cpp/src/tests/cluster_authentication_soak.cpp
parenta496df01eec8f7c9989c6ec9fe89ea864a6b9cf9 (diff)
downloadqpid-python-ba91599c45eeb8f3578cd34092302b2394b9ea69.tar.gz
Jira QPID-2617 -- make sasl-based tests config files relocatable
Before this change, sasl-based testing cannot be fully automated because the sasl db must be located in the standard installation location of /etc/sasl2. * Created a new directory "sasl_config" under cpp/src/tests * added a new makefile fragment "sasl.mk" to cpp/src/Makefile.am conditionally included basedon HAVE_SASL, which is defined by configure. ( NOTE: should be in cpp/src/tests/Makefile.am, but getting an "saslpasswd2: generic failure" when I try that. ) * The sasl.mk fragment uses saslpasswd2 to create a sasl db in cpp/src/tests/sasl_config that defines two users with eponymous passwords. * In test cluster_authentication_soak.cpp, make the cluster name random. * make SaslAuthenticator code accept and use a config path * give cluster_authentication_soak self-test capability. the test is meant to detect two problems: - broker failure - perftest hang so give it flags that will force either of those conditions. This allows me to (anually) ensure that the test really does detect those conditions when they occur. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@947748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests/cluster_authentication_soak.cpp')
-rw-r--r--qpid/cpp/src/tests/cluster_authentication_soak.cpp121
1 files changed, 93 insertions, 28 deletions
diff --git a/qpid/cpp/src/tests/cluster_authentication_soak.cpp b/qpid/cpp/src/tests/cluster_authentication_soak.cpp
index ccf4d278c0..6963438d5f 100644
--- a/qpid/cpp/src/tests/cluster_authentication_soak.cpp
+++ b/qpid/cpp/src/tests/cluster_authentication_soak.cpp
@@ -44,6 +44,10 @@
#include <qpid/client/Connection.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
@@ -64,32 +68,42 @@ typedef vector<ForkedBroker *> brokerVector;
-int newbiePort = 0;
+int runSilent = 1;
+int newbiePort = 0;
+
+void
+makeClusterName ( string & s ) {
+ stringstream ss;
+ ss << "authenticationSoakCluster_" << Uuid(true).str();
+ s = ss.str();
+}
void
-startBroker ( brokerVector & brokers ,
- int brokerNumber ) {
- stringstream portSS, prefix;
+startBroker ( brokerVector & brokers , int brokerNumber, string const & clusterName ) {
+ stringstream prefix, clusterArg;
prefix << "soak-" << brokerNumber;
+ clusterArg << "--cluster-name=" << clusterName;
+
std::vector<std::string> argv;
argv.push_back ("../qpidd");
argv.push_back ("--no-module-dir");
argv.push_back ("--load-module=../.libs/cluster.so");
- argv.push_back ("--cluster-name=micks_test_cluster");
- argv.push_back ("--cluster-username=guest");
- argv.push_back ("--cluster-password=guest");
+ argv.push_back (clusterArg.str().c_str());
+ argv.push_back ("--cluster-username=zig");
+ argv.push_back ("--cluster-password=zig");
argv.push_back ("--cluster-mechanism=ANONYMOUS");
- argv.push_back ("TMP_DATA_DIR");
+ argv.push_back ("--sasl-config=./sasl_config");
argv.push_back ("--auth=yes");
argv.push_back ("--mgmt-enable=yes");
argv.push_back ("--log-prefix");
argv.push_back (prefix.str());
argv.push_back ("--log-to-file");
argv.push_back (prefix.str()+".log");
+ argv.push_back ("TMP_DATA_DIR");
ForkedBroker * newbie = new ForkedBroker (argv);
newbiePort = newbie->getPort();
@@ -100,7 +114,7 @@ startBroker ( brokerVector & brokers ,
bool
-runPerftest ( ) {
+runPerftest ( bool hangTest ) {
stringstream portSs;
portSs << newbiePort;
@@ -111,9 +125,9 @@ runPerftest ( ) {
argv.push_back ( "-p" );
argv.push_back ( portSs.str().c_str() );
argv.push_back ( "--username" );
- argv.push_back ( "guest" );
+ argv.push_back ( "zig" );
argv.push_back ( "--password" );
- argv.push_back ( "guest" );
+ argv.push_back ( "zig" );
argv.push_back ( "--mechanism" );
argv.push_back ( "DIGEST-MD5" );
argv.push_back ( "--count" );
@@ -133,6 +147,12 @@ runPerftest ( ) {
return false;
}
else {
+ if ( hangTest ) {
+ if ( ! runSilent )
+ cerr << "Pausing perftest " << pid << endl;
+ kill ( pid, 19 );
+ }
+
struct timeval startTime,
currentTime,
duration;
@@ -140,7 +160,7 @@ runPerftest ( ) {
gettimeofday ( & startTime, 0 );
while ( 1 ) {
- sleep ( 5 );
+ sleep ( 2 );
int status;
int returned_pid = waitpid ( pid, &status, WNOHANG );
if ( returned_pid == pid ) {
@@ -171,14 +191,9 @@ runPerftest ( ) {
bool
allBrokersAreAlive ( brokerVector & brokers ) {
- for ( unsigned int i = 0; i < brokers.size(); ++ i ) {
- pid_t pid = brokers[i]->getPID();
- int status;
- int value;
- if ( (value = waitpid ( pid, &status, WNOHANG ) ) ) {
- return false;
- }
- }
+ for ( unsigned int i = 0; i < brokers.size(); ++ i )
+ if ( ! brokers[i]->isRunning() )
+ return false;
return true;
}
@@ -186,10 +201,23 @@ allBrokersAreAlive ( brokerVector & brokers ) {
+
void
killAllBrokers ( brokerVector & brokers ) {
- for ( unsigned int i = 0; i < brokers.size(); ++ i )
+ for ( unsigned int i = 0; i < brokers.size(); ++ i ) {
brokers[i]->kill ( 9 );
+ }
+}
+
+
+
+
+void
+killOneBroker ( brokerVector & brokers ) {
+ int doomedBroker = getpid() % brokers.size();
+ cout << "Killing broker " << brokers[doomedBroker]->getPID() << endl;
+ brokers[doomedBroker]->kill ( 9 );
+ sleep ( 2 );
}
@@ -201,15 +229,36 @@ using namespace qpid::tests;
+/*
+ * Please note that this test has self-test capability.
+ * It is intended to detect
+ * 1. perftest hangs.
+ * 2. broker deaths
+ * Both of these condtions can be forced when running manually
+ * to ensure that the test really does detect them.
+ * See command-line arguments 3 and 4.
+ */
int
main ( int argc, char ** argv )
{
- int n_iterations = argc > 0 ? atoi(argv[1]) : 1;
+ int n_iterations = argc > 1 ? atoi(argv[1]) : 1;
+ runSilent = argc > 2 ? atoi(argv[2]) : 1; // default to silent
+ int killBroker = argc > 3 ? atoi(argv[3]) : 0; // Force the kill of one broker.
+ int hangTest = argc > 4 ? atoi(argv[4]) : 0; // Force the first perftest to hang.
int n_brokers = 3;
brokerVector brokers;
+ #ifndef HAVE_SASL
+ if ( ! runSilent )
+ cout << "No SASL support. cluster_authentication_soak disabled.";
+ return 0;
+ #endif
+
+ srand ( getpid() );
+ string clusterName;
+ makeClusterName ( clusterName );
for ( int i = 0; i < n_brokers; ++ i ) {
- startBroker ( brokers, i );
+ startBroker ( brokers, i, clusterName );
}
sleep ( 3 );
@@ -221,22 +270,38 @@ main ( int argc, char ** argv )
* set to 1.
*/
for ( int iteration = 0; iteration < n_iterations; ++ iteration ) {
- if ( ! runPerftest ( ) ) {
- cerr << "qpid-perftest " << iteration << " failed.\n";
+ if ( ! runPerftest ( hangTest ) ) {
+ if ( ! runSilent )
+ cerr << "qpid-perftest " << iteration << " failed.\n";
return 1;
}
if ( ! ( iteration % 10 ) ) {
- cerr << "qpid-perftest " << iteration << " complete. -------------- \n";
+ if ( ! runSilent )
+ cerr << "qpid-perftest " << iteration << " complete. -------------- \n";
}
}
- cerr << "\nqpid-perftest " << n_iterations << " iterations complete. -------------- \n\n";
+ if ( ! runSilent )
+ cerr << "\nqpid-perftest " << n_iterations << " iterations complete. -------------- \n\n";
+
+ /* If the command-line tells us to kill a broker, do
+ * it now. Use this option to prove that this test
+ * really can detect broker-deaths.
+ */
+ if ( killBroker ) {
+ killOneBroker ( brokers );
+ }
if ( ! allBrokersAreAlive ( brokers ) ) {
- cerr << "not all brokers are alive.\n";
+ if ( ! runSilent )
+ cerr << "not all brokers are alive.\n";
+ killAllBrokers ( brokers );
return 2;
}
killAllBrokers ( brokers );
+ if ( ! runSilent )
+ cout << "success.\n";
+
return 0;
}