]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ErasureCode: fix plugin loading threaded test 628/head
authorLoic Dachary <loic@dachary.org>
Tue, 24 Sep 2013 13:51:08 +0000 (15:51 +0200)
committerLoic Dachary <loic@dachary.org>
Tue, 24 Sep 2013 14:07:31 +0000 (16:07 +0200)
The TEST_F(ErasureCodePluginRegistryTest, factory_mutex) was bugous and
only succeeded by chance. The sleep was on the factory constructor which
was never called. An erasure code plugin that hangs forever on load is
created instead.

The sleep_forever.detach is replaced by pthread_cancel to interrupt the
thread that hangs forever. If not, gtest will try to join the thread and
never exit.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/test/Makefile.am
src/test/osd/ErasureCodeExample.h
src/test/osd/ErasureCodePluginExample.cc
src/test/osd/ErasureCodePluginHangs.cc [new file with mode: 0644]
src/test/osd/TestErasureCodeExample.cc
src/test/osd/TestErasureCodePlugin.cc

index 5b709d248a81247f4404f6c9b3d9d0021f11a9fa..a3127be9455c236bf97413e3f74ae90afb3ac18b 100644 (file)
@@ -323,6 +323,13 @@ libec_missing_entry_point_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS)
 libec_missing_entry_point_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__erasure_code_.*'
 erasure_codelib_LTLIBRARIES += libec_missing_entry_point.la
 
+libec_hangs_la_SOURCES = test/osd/ErasureCodePluginHangs.cc
+libec_hangs_la_CFLAGS = ${AM_CFLAGS}
+libec_hangs_la_CXXFLAGS= ${AM_CXXFLAGS}
+libec_hangs_la_LIBADD = $(PTHREAD_LIBS) $(EXTRALIBS)
+libec_hangs_la_LDFLAGS = ${AM_LDFLAGS} -export-symbols-regex '.*__erasure_code_.*'
+erasure_codelib_LTLIBRARIES += libec_hangs.la
+
 libec_fail_to_initialize_la_SOURCES = test/osd/ErasureCodePluginFailToInitialize.cc
 libec_fail_to_initialize_la_CFLAGS = ${AM_CFLAGS}
 libec_fail_to_initialize_la_CXXFLAGS= ${AM_CXXFLAGS}
index 95d79feb923f652860e10b18e07e4241e3891c83..0fd55187559f4164036b4646764b95c4b689f645 100644 (file)
 
 class ErasureCodeExample : public ErasureCodeInterface {
 public:
-  useconds_t delay;
-  ErasureCodeExample(const map<std::string,std::string> &parameters) :
-    delay(0)
-  {
-    if (parameters.find("usleep") != parameters.end()) {
-      std::istringstream ss(parameters.find("usleep")->second);
-      ss >> delay;
-      usleep(delay);
-    }
-  }
-
   virtual ~ErasureCodeExample() {}
   
   virtual int minimum_to_decode(const set<int> &want_to_read,
index 1543b1cdaedea4a937d3930b33976a73340a631e..6ae61c0a18de98d04b6609247a095c9f0519fc2a 100644 (file)
@@ -14,6 +14,8 @@
  * 
  */
 
+#include <unistd.h>
+
 #include "osd/ErasureCodePlugin.h"
 #include "ErasureCodeExample.h"
 
@@ -22,7 +24,7 @@ public:
   virtual int factory(const map<std::string,std::string> &parameters,
                       ErasureCodeInterfaceRef *erasure_code)
   {
-    *erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample(parameters));
+    *erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample());
     return 0;
   }
 };
diff --git a/src/test/osd/ErasureCodePluginHangs.cc b/src/test/osd/ErasureCodePluginHangs.cc
new file mode 100644 (file)
index 0000000..ea73786
--- /dev/null
@@ -0,0 +1,24 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ * 
+ */
+
+#include <unistd.h>
+#include "osd/ErasureCodePlugin.h"
+
+int __erasure_code_init(char *plugin_name)
+{
+  sleep(1000);
+  return 0;
+}
index 6866dfdbb9ff11658cafd92a20e4fdf9b3f754ec..f12e80c8cd043a132f58f912333d52f0e291729a 100644 (file)
 #include "global/global_context.h"
 #include "gtest/gtest.h"
 
-TEST(ErasureCodeExample, constructor)
-{
-  map<std::string,std::string> parameters;
-  {
-    ErasureCodeExample example(parameters);
-    EXPECT_EQ(0u, example.delay);
-  }
-  parameters["usleep"] = "10";
-  {
-    ErasureCodeExample example(parameters);
-    EXPECT_EQ(10u, example.delay);
-  }
-}
-
 TEST(ErasureCodeExample, minimum_to_decode)
 {
-  map<std::string,std::string> parameters;
-  ErasureCodeExample example(parameters);
+  ErasureCodeExample example;
   set<int> available_chunks;
   set<int> want_to_read;
   want_to_read.insert(1);
@@ -72,8 +57,7 @@ TEST(ErasureCodeExample, minimum_to_decode)
 
 TEST(ErasureCodeExample, minimum_to_decode_with_cost)
 {
-  map<std::string,std::string> parameters;
-  ErasureCodeExample example(parameters);
+  ErasureCodeExample example;
   map<int,int> available;
   set<int> want_to_read;
   want_to_read.insert(1);
@@ -117,8 +101,7 @@ TEST(ErasureCodeExample, minimum_to_decode_with_cost)
 
 TEST(ErasureCodeExample, encode_decode)
 {
-  map<std::string,std::string> parameters;
-  ErasureCodeExample example(parameters);
+  ErasureCodeExample example;
 
   bufferlist in;
   in.append("ABCDE");
index ba7d13fbd2d668ce271a82286dbf2baa82db6d16..46ed4b1730dc9fc99ec40a7214b611c5742e9d2c 100644 (file)
@@ -28,19 +28,12 @@ protected:
 
   class Thread_factory : public Thread {
   public:
-    useconds_t delay;
-
-    Thread_factory(useconds_t _delay) :
-      delay(_delay)
-    {}
-
     virtual void *entry() {
       map<std::string,std::string> parameters;
       parameters["erasure-code-directory"] = ".libs";
-      parameters["usleep"] = delay;
       ErasureCodePluginRegistry &instance = ErasureCodePluginRegistry::instance();
       ErasureCodeInterfaceRef erasure_code;
-      instance.factory("example", parameters, &erasure_code);
+      instance.factory("hangs", parameters, &erasure_code);
       return NULL;
     }
   };
@@ -58,7 +51,7 @@ TEST_F(ErasureCodePluginRegistryTest, factory_mutex) {
   //
   useconds_t delay = 0;
   const useconds_t DELAY_MAX = 20 * 1000 * 1000;
-  Thread_factory sleep_forever(1024 * 1024 * 1024);
+  Thread_factory sleep_forever;
   sleep_forever.create();
   do {
     cout << "Trying (1) with delay " << delay << "us\n";
@@ -71,7 +64,8 @@ TEST_F(ErasureCodePluginRegistryTest, factory_mutex) {
 
   EXPECT_FALSE(instance.lock.TryLock());
 
-  EXPECT_EQ(0, sleep_forever.detach());
+  EXPECT_EQ(0, pthread_cancel(sleep_forever.get_thread_id()));
+  EXPECT_EQ(0, sleep_forever.join());
 }
 
 TEST_F(ErasureCodePluginRegistryTest, all)