diff options
author | Alan Conway <aconway@apache.org> | 2008-07-08 15:22:37 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-07-08 15:22:37 +0000 |
commit | 43664d69dc90c128ad3f73327ac8331b02d7a38c (patch) | |
tree | e92629756eb899c3ad6cdac129a84e1966b4db40 /cpp/src/tests | |
parent | 50d4782e2f3676723a2df5bf6a420d45fb55467d (diff) | |
download | qpid-python-43664d69dc90c128ad3f73327ac8331b02d7a38c.tar.gz |
Removed static Cpg::handlers, fixed ForkedBroker shutdown.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@674855 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/ForkedBroker.h | 33 | ||||
-rw-r--r-- | cpp/src/tests/cluster_test.cpp | 10 |
2 files changed, 33 insertions, 10 deletions
diff --git a/cpp/src/tests/ForkedBroker.h b/cpp/src/tests/ForkedBroker.h index c2f3346296..5fb1ce8478 100644 --- a/cpp/src/tests/ForkedBroker.h +++ b/cpp/src/tests/ForkedBroker.h @@ -22,6 +22,7 @@ * */ +#include "qpid/Exception.h" #include "qpid/sys/Fork.h" #include "qpid/log/Logger.h" #include "qpid/broker/Broker.h" @@ -48,7 +49,7 @@ * */ class ForkedBroker : public qpid::sys::ForkWithMessage { - pid_t childPid; + pid_t pid; uint16_t port; qpid::broker::Broker::Options opts; std::string prefix; @@ -56,22 +57,33 @@ class ForkedBroker : public qpid::sys::ForkWithMessage { public: struct ChildExit {}; // Thrown in child processes. - ForkedBroker(const qpid::broker::Broker::Options& opts_, const std::string& prefix_=std::string()) - : childPid(0), port(0), opts(opts_), prefix(prefix_) { fork(); } + ForkedBroker(const qpid::broker::Broker::Options& opts_=qpid::broker::Broker::Options(), + const std::string& prefix_=std::string()) + : pid(0), port(0), opts(opts_), prefix(prefix_) { fork(); } - ~ForkedBroker() { stop(); } + ~ForkedBroker() { + try { stop(); } + catch(const std::exception& e) { + QPID_LOG(error, e.what()); + } + } void stop() { - if (childPid > 0) { - ::kill(childPid, SIGINT); - ::waitpid(childPid, 0, 0); + if (pid > 0) { // I am the parent, clean up children. + if (::kill(pid, SIGINT) < 0) + throw qpid::Exception(QPID_MSG("Can't kill process " << pid << ": " << qpid::strError(errno))); + int status = 0; + if (::waitpid(pid, &status, 0) < 0) + throw qpid::Exception(QPID_MSG("Waiting for process " << pid << ": " << qpid::strError(errno))); + if (WEXITSTATUS(status) != 0) + throw qpid::Exception(QPID_MSG("Process " << pid << " exited with status: " << WEXITSTATUS(status))); } } - void parent(pid_t pid) { - childPid = pid; + void parent(pid_t pid_) { + pid = pid_; qpid::log::Logger::instance().setPrefix("parent"); - std::string portStr = wait(2); + std::string portStr = wait(5); port = boost::lexical_cast<uint16_t>(portStr); } @@ -88,6 +100,7 @@ class ForkedBroker : public qpid::sys::ForkWithMessage { // Force exit in the child process, otherwise we will try to // carry with parent tests. + broker.reset(); // Run broker dtor before we exit. exit(0); } diff --git a/cpp/src/tests/cluster_test.cpp b/cpp/src/tests/cluster_test.cpp index 2fa7cd325d..82d18aceff 100644 --- a/cpp/src/tests/cluster_test.cpp +++ b/cpp/src/tests/cluster_test.cpp @@ -147,6 +147,16 @@ QPID_AUTO_TEST_CASE(CpgBasic) { } +QPID_AUTO_TEST_CASE(testForkedBroker) { + // Verify the ForkedBroker works as expected. + Broker::Options opts; + opts.auth="no"; + opts.noDataDir=true; + ForkedBroker broker(opts); + Client c(broker.getPort()); + BOOST_CHECK_EQUAL("direct", c.session.exchangeQuery("amq.direct").getType()); +} + QPID_AUTO_TEST_CASE(testWiringReplication) { ClusterFixture cluster(2); // FIXME aconway 2008-07-02: 3 brokers Client c0(cluster[0].getPort()); |