adds handshake delay and test doneness check

This commit is contained in:
Peter Thorson
2012-06-05 08:26:06 -05:00
parent 1d3942622a
commit 2d12256c7c
3 changed files with 27 additions and 3 deletions

View File

@@ -94,6 +94,11 @@ void request::process(unsigned int id) {
boost::thread t(boost::bind(&client::run, &e, true));
size_t handshake_delay;
if(!wscmd::extract_number<size_t>(command, "handshake_delay",handshake_delay)) {
handshake_delay = 10;
}
// create connections
for (size_t i = 0; i < connection_count; i++) {
client::connection_ptr con;
@@ -103,6 +108,8 @@ void request::process(unsigned int id) {
shandler->on_connect(con);
e.connect(con);
boost::this_thread::sleep(boost::posix_time::milliseconds(handshake_delay));
}
for (;;) {
@@ -111,12 +118,18 @@ void request::process(unsigned int id) {
// check for too few connections
shandler->maintenance();
bool quit = shandler->maintenance();
// check for done-ness
if (quit) {
break;
}
sleep(1);
}
e.end_perpetual();
t.join();
}
writer->write(prepare_response("test_complete",""));

View File

@@ -179,15 +179,24 @@ std::string stress_handler::get_data() const {
return data.str();
}
void stress_handler::maintenance() {
bool stress_handler::maintenance() {
std::list<connection_ptr> to_process;
{
boost::lock_guard<boost::mutex> lock(m_lock);
bool quit = true;
std::map<connection_ptr,con_data>::iterator it;
for (it = m_con_data.begin(); it != m_con_data.end(); it++) {
to_process.push_back((*it).first);
if ((*it).first->get_state() != websocketpp::session::state::CLOSED) {
quit = false;
}
}
if (quit) {
return true;
}
}
@@ -220,4 +229,6 @@ void stress_handler::maintenance() {
close(con);
}
}
return false;
}

View File

@@ -116,7 +116,7 @@ public:
void end();
std::string get_data() const;
virtual void maintenance();
virtual bool maintenance();
protected:
size_t m_current_connections;
size_t m_max_connections;