]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test_msgr: Add random usleep to Dispatcher impl
authorHaomai Wang <haomaiwang@gmail.com>
Thu, 8 Jan 2015 14:12:11 +0000 (22:12 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Thu, 15 Jan 2015 19:07:11 +0000 (03:07 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/test/msgr/test_msgr.cc

index ef8c28cab2500b6b60d74805ae9c2944f1c60999..0928f5c7dc8fb4970fc7ef2db6afe215eb65781d 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <iostream>
 #include <unistd.h>
+#include <stdlib.h>
 #include <time.h>
 #include "common/Mutex.h"
 #include "common/Cond.h"
@@ -574,9 +575,11 @@ class MarkdownDispatcher : public Dispatcher {
 
   void ms_handle_fast_connect(Connection *con) {
     cerr << __func__ << con << std::endl;
+    Mutex::Locker l(lock);
     conns.insert(con);
   }
   void ms_handle_fast_accept(Connection *con) {
+    Mutex::Locker l(lock);
     conns.insert(con);
   }
   bool ms_dispatch(Message *m) {
@@ -588,6 +591,7 @@ class MarkdownDispatcher : public Dispatcher {
       return true;
 
     last_mark = true;
+    usleep(rand() % 500);
     for (set<Connection*>::iterator it = conns.begin(); it != conns.end(); ++it) {
       if ((*it) != m->get_connection().get()) {
         (*it)->mark_down();
@@ -601,10 +605,13 @@ class MarkdownDispatcher : public Dispatcher {
   }
   bool ms_handle_reset(Connection *con) {
     cerr << __func__ << con << std::endl;
+    Mutex::Locker l(lock);
     conns.erase(con);
+    usleep(rand() % 500);
     return true;
   }
   void ms_handle_remote_reset(Connection *con) {
+    Mutex::Locker l(lock);
     conns.erase(con);
     cerr << __func__ << con << std::endl;
   }