Solve legacy problem with clear operation (coredump with running threads)
[anna.git] / include / anna / testing / TestStep.hpp
index 4442f66..844b6be 100644 (file)
@@ -13,6 +13,7 @@
 #include <string>
 #include <vector>
 #include <thread>
+#include <atomic>
 
 // Project
 #include <anna/core/DataBlock.hpp>
@@ -102,6 +103,7 @@ class TestStepTimeout : public TestStep {
 
   public:
     TestStepTimeout(TestCase *testCase) : TestStep(testCase), a_timeout(0), a_timer(NULL) { a_type = Type::Timeout; }
+    ~TestStepTimeout() { do_reset(); }
 
     // setter & getters
     void setTimeout(const anna::Millisecond &t) throw() { a_timeout = t; }
@@ -133,7 +135,7 @@ class TestStepSendDiameterXml : public TestStep {
       a_expired(false),
       a_originHost(NULL),
       a_waitForRequestStepNumber(-1) {;}
-    ~TestStepSendDiameterXml() {;}
+    ~TestStepSendDiameterXml() { do_reset(); }
 
     // setter & getters
     void setOriginHost(anna::diameter::comm::OriginHost *host) throw() { a_originHost = host; }
@@ -167,6 +169,7 @@ class TestStepDelay : public TestStep {
 
   public:
     TestStepDelay(TestCase *testCase) : TestStep(testCase), a_delay(0), a_timer(NULL) { a_type = Type::Delay; }
+    ~TestStepDelay() { do_reset(); }
 
     // setter & getters
     void setDelay(const anna::Millisecond &d) throw() { a_delay = d; }
@@ -193,7 +196,7 @@ class TestStepWaitDiameter : public TestStep {
       a_clientSession = NULL;
       a_serverSession = NULL;
     }
-    ~TestStepWaitDiameter() {;}
+    ~TestStepWaitDiameter() { do_reset(); }
 
     // setter & getters
     void setCondition(bool fromEntity,
@@ -226,7 +229,7 @@ class TestStepCmd : public TestStep {
 
   std::string a_script;
   std::thread a_thread;
-  bool a_threadRunning;
+  std::atomic<bool> a_threadRunning;
   bool a_threadDeprecated;
   int a_resultCode;
   std::string a_errorMsg;
@@ -236,9 +239,13 @@ class TestStepCmd : public TestStep {
 
   public:
     TestStepCmd(TestCase *testCase) : TestStep(testCase), a_threadRunning(false), a_threadDeprecated(false), a_resultCode(-2)/*, a_output("")*/, a_errorMsg(""), a_childPid(-1) { a_type = Type::Cmd; }
+    ~TestStepCmd() { do_reset(); }
 
     // setter & getters
-    void setThreadRunning(bool running) throw() { a_threadRunning = running; }
+    void setThreadRunning() throw() { a_threadRunning = true; }
+    void setThreadNotRunning() throw() { a_threadRunning = false; }
+    bool threadRunning() const throw() { return a_threadRunning; }
+    bool threadNotRunning() const throw() { return !a_threadRunning; }
 
     void setResultCode(int rc) throw() { a_resultCode = rc; }
     int getResultCode() const throw() { return a_resultCode; }
@@ -266,6 +273,7 @@ class TestStepIpLimit : public TestStep {
 
   public:
     TestStepIpLimit(TestCase *testCase) : TestStep(testCase), a_ipLimit(1) { a_type = Type::IpLimit; }
+    ~TestStepIpLimit() { do_reset(); }
 
     // setter & getters
     void setIpLimit(unsigned int limit) throw() { a_ipLimit = limit; }