diff options
author | Alan Conway <aconway@apache.org> | 2007-07-23 13:08:16 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-07-23 13:08:16 +0000 |
commit | 1a469b992ef2f28d98f43e63cf4d520c1bf830a4 (patch) | |
tree | c743052e2d2ab10a28960234e3efd3534cdb14c1 /cpp/src/tests | |
parent | 4ab144d3d0a48a4abc1814e3244ef830344f19b2 (diff) | |
download | qpid-python-1a469b992ef2f28d98f43e63cf4d520c1bf830a4.tar.gz |
* src/tests/cluster.mk: Enable cluster test.
* src/tests/Cluster.h (class TestHandler):
Fixed race in TestHandler::waitFor
* src/tests/Cluster.cpp
- Allow separate start of parent and child processes.
* src/qpid/Options.cpp (parse): Skip argv parsing if argc=0.
* src/qpid/cluster/Cluster.cpp (configChange): assert group name.
* src/qpid/cluster/Cpg.cpp, .h: Additional logging
* src/qpid/framing/AMQFrame.cpp: Initialize all fields in ctor,
avoid valgrind warning.
* src/qpid/log/Logger.cpp: Initialize singleton automatically
from environment so logging can be used on tests.
* src/qpid/sys/Time.h: Avoid overflow in AbsTime(t, TIME_INFINITE)
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@558710 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests')
-rw-r--r-- | cpp/src/tests/Cluster.cpp | 29 | ||||
-rw-r--r-- | cpp/src/tests/Cluster.h | 19 | ||||
-rw-r--r-- | cpp/src/tests/Cpg.cpp | 4 | ||||
-rw-r--r-- | cpp/src/tests/cluster.mk | 9 |
4 files changed, 35 insertions, 26 deletions
diff --git a/cpp/src/tests/Cluster.cpp b/cpp/src/tests/Cluster.cpp index 56e17e06db..b22f312038 100644 --- a/cpp/src/tests/Cluster.cpp +++ b/cpp/src/tests/Cluster.cpp @@ -30,8 +30,6 @@ static const ProtocolVersion VER; -using namespace qpid::log; - /** Verify membership in a cluster with one member. */ BOOST_AUTO_TEST_CASE(testClusterOne) { TestCluster cluster("clusterOne", "amqp:one:1"); @@ -55,10 +53,15 @@ BOOST_AUTO_TEST_CASE(testClusterOne) { /** Fork a process to test a cluster with two members */ BOOST_AUTO_TEST_CASE(testClusterTwo) { - pid_t pid=fork(); - BOOST_REQUIRE(pid >= 0); - if (pid) { // Parent, see Cluster_child.cpp for child. - TestCluster cluster("clusterTwo", "amqp::1"); + bool nofork=getenv("NOFORK") != 0; + pid_t pid=0; + if (!nofork) { + pid = fork(); + BOOST_REQUIRE(pid >= 0); + } + if (pid || nofork) { // Parent + BOOST_MESSAGE("Parent start"); + TestCluster cluster("clusterTwo", "amqp:parent:1"); BOOST_REQUIRE(cluster.waitFor(2)); // Myself and child. // Exchange frames with child. @@ -74,12 +77,14 @@ BOOST_AUTO_TEST_CASE(testClusterTwo) { BOOST_REQUIRE(cluster.received.waitFor(2)); BOOST_CHECK_TYPEID_EQUAL(ChannelOkBody, *cluster.received[1].frame.getBody()); - // Wait for child to exit. - int status; - BOOST_CHECK_EQUAL(::wait(&status), pid); - BOOST_CHECK_EQUAL(0, status); - BOOST_CHECK(cluster.waitFor(1)); - BOOST_CHECK_EQUAL(1u, cluster.size()); + if (!nofork) { + // Wait for child to exit. + int status; + BOOST_CHECK_EQUAL(::wait(&status), pid); + BOOST_CHECK_EQUAL(0, status); + BOOST_CHECK(cluster.waitFor(1)); + BOOST_CHECK_EQUAL(1u, cluster.size()); + } } else { // Child BOOST_REQUIRE(execl("./Cluster_child", "./Cluster_child", NULL)); diff --git a/cpp/src/tests/Cluster.h b/cpp/src/tests/Cluster.h index bf6d1c2a64..c2909e0c1b 100644 --- a/cpp/src/tests/Cluster.h +++ b/cpp/src/tests/Cluster.h @@ -48,20 +48,25 @@ using namespace boost; void null_deleter(void*) {} template <class T> -struct TestHandler : public Handler<T&>, public vector<T>, public Monitor +class TestHandler : public Handler<T&>, public vector<T> { + Monitor lock; + + public: void handle(T& frame) { - Mutex::ScopedLock l(*this); + Mutex::ScopedLock l(lock); push_back(frame); - notifyAll(); + BOOST_MESSAGE(getpid()<<" TestHandler::handle: " << this->size()); + lock.notifyAll(); } bool waitFor(size_t n) { - Mutex::ScopedLock l(*this); - AbsTime deadline(now(), 5*TIME_SEC); - while (vector<T>::size() != n && wait(deadline)) + Mutex::ScopedLock l(lock); + BOOST_MESSAGE(getpid()<<" TestHandler::waitFor("<<n<<") "<<this->size()); + AbsTime deadline(now(), 2*TIME_SEC); + while (vector<T>::size() < n && lock.wait(deadline)) ; - return vector<T>::size() == n; + return vector<T>::size() >= n; } }; diff --git a/cpp/src/tests/Cpg.cpp b/cpp/src/tests/Cpg.cpp index ec98ca4fc2..7c0d6f7fd0 100644 --- a/cpp/src/tests/Cpg.cpp +++ b/cpp/src/tests/Cpg.cpp @@ -82,11 +82,11 @@ struct Callback : public Cpg::Handler { } }; -BOOST_AUTO_TEST_CASE(Cpg_basic) { +BOOST_AUTO_TEST_CASE(CpgBasic) { // Verify basic functionality of cpg. This will catch any // openais configuration or permission errors. // - Cpg::Name group("foo"); + Cpg::Name group("CpgBasic"); Callback cb(group.str()); Cpg cpg(cb); cpg.join(group); diff --git a/cpp/src/tests/cluster.mk b/cpp/src/tests/cluster.mk index 506624569f..7407565f62 100644 --- a/cpp/src/tests/cluster.mk +++ b/cpp/src/tests/cluster.mk @@ -20,11 +20,10 @@ check_PROGRAMS+=Cpg Cpg_SOURCES=Cpg.cpp Cpg_LDADD=$(lib_cluster) -lboost_unit_test_framework -# FIXME aconway 2007-07-19: -# TESTS+=Cluster -# check_PROGRAMS+=Cluster -# Cluster_SOURCES=Cluster.cpp Cluster.h -# Cluster_LDADD=$(lib_cluster) -lboost_unit_test_framework +TESTS+=Cluster +check_PROGRAMS+=Cluster +Cluster_SOURCES=Cluster.cpp Cluster.h +Cluster_LDADD=$(lib_cluster) -lboost_unit_test_framework check_PROGRAMS+=Cluster_child Cluster_child_SOURCES=Cluster_child.cpp Cluster.h |