From: Marc Cromme Date: Sat, 8 Oct 2005 16:32:01 +0000 (+0000) Subject: added multithreaded session test using 10 threads and 100 id updates each X-Git-Tag: YP2.0.0.2~238 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=4d5febdded4cf09681bf9491789d1c7bec9cb3a6;p=metaproxy-moved-to-github.git added multithreaded session test using 10 threads and 100 id updates each --- diff --git a/src/Makefile.am b/src/Makefile.am index 7ebc614..6e72261 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.11 2005-10-07 22:46:16 marc Exp $ +## $Id: Makefile.am,v 1.12 2005-10-08 16:32:01 marc Exp $ MAINTAINERCLEANFILES = Makefile.in config.in config.hpp @@ -8,8 +8,9 @@ AM_CXXFLAGS = $(YAZPPINC) $(XSLT_CFLAGS) YP2_INCHPP = session.hpp package.hpp filter.hpp router.hpp bin_PROGRAMS = -check_PROGRAMS = test_filter1 test_filter2 test_session1 \ - test_thread_pool_observer test_boost_threads +check_PROGRAMS = test_filter1 test_filter2 \ + test_session1 test_session2 \ + test_thread_pool_observer test_boost_threads noinst_PROGRAMS = p2 TESTS=$(check_PROGRAMS) @@ -17,6 +18,7 @@ TESTS=$(check_PROGRAMS) test_filter1_SOURCES=test_filter1.cpp $(YP2_INCHPP) test_filter2_SOURCES=test_filter2.cpp $(YP2_INCHPP) test_session1_SOURCES=test_session1.cpp $(YP2_INCHPP) +test_session2_SOURCES=test_session2.cpp $(YP2_INCHPP) test_boost_threads_SOURCES=test_boost_threads.cpp test_thread_pool_observer_SOURCES = test_thread_pool_observer.cpp \ thread_pool_observer.cpp thread_pool_observer.h @@ -34,6 +36,7 @@ LDADD= $(YAZPPLALIB) $(XSLT_LIBS) test_filter1_LDADD = $(LDADD) -lboost_unit_test_framework test_filter2_LDADD = $(LDADD) -lboost_unit_test_framework test_session1_LDADD = $(LDADD) -lboost_unit_test_framework +test_session2_LDADD = $(LDADD) -lboost_unit_test_framework test_boost_threads_LDADD = $(LDADD) -lboost_unit_test_framework diff --git a/src/test_session2.cpp b/src/test_session2.cpp new file mode 100644 index 0000000..4f4623c --- /dev/null +++ b/src/test_session2.cpp @@ -0,0 +1,80 @@ +#include "session.hpp" + +#include +#include + +#include +#include + +#define BOOST_AUTO_TEST_MAIN +#include + +using namespace boost::unit_test; + +boost::mutex io_mutex; + +class Worker +{ + public: + Worker(yp2::Session *session, int nr = 0) + : m_session(session), m_nr(nr){}; + + void operator() (void) { + for (int i=0; i < 100; ++i) + { + m_id = m_session->id(); + //print(); + } + } + + void print() + { + boost::mutex::scoped_lock scoped_lock(io_mutex); + std::cout << "Worker " << m_nr + << " session.id() " << m_id << std::endl; + } + + private: + yp2::Session *m_session; + int m_nr; + int m_id; +}; + + + +BOOST_AUTO_TEST_CASE( testsession2 ) +{ + + // test session + try { + yp2::Session session; + + const int num_threads = 10; + boost::thread_group thrds; + + for (int i=0; i < num_threads; ++i) + { + Worker w(&session, i); + thrds.add_thread(new boost::thread(w)); + } + thrds.join_all(); + + BOOST_CHECK (session.id() == 1001); + + } + catch (std::exception &e) { + std::cout << e.what() << "\n"; + BOOST_CHECK (false); + } + catch (...) { + BOOST_CHECK (false); + } +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */