]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Test of new holdRequests activeRequests
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 23 Nov 2017 15:25:51 +0000 (16:25 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 23 Nov 2017 15:25:51 +0000 (16:25 +0100)
idl/SALOME_SDS.idl
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.hxx
src/SALOMESDS/SALOMESDS_Exception.cxx
src/SALOMESDS/SALOMESDS_Exception.hxx
src/SALOMESDS/TestSalomeSDS.py

index 2f0f26ed67d7994c92203b8363ef1a806671e4b8..51048ba1a515716ec070f6a07c080c2b8e9ff838 100644 (file)
@@ -89,6 +89,7 @@ module SALOME
     ByteVec fetchSerializedContent(in string varName) raises (SALOME::SALOME_Exception);
     SeqOfByteVec getAllKeysOfVarWithTypeDict(in string varName) raises (SALOME::SALOME_Exception);
     RequestSwitcher getRequestSwitcher();
+    void takeANap(in double napDurationInSec) raises (SALOME::SALOME_Exception);
   };
 
   interface DataScopeServer : DataScopeServerBase
index bacea68e4c529f83020180c3ea7c6fbb26ffd9a6..a8e879a497d62c710483dcb1d0f5c0b5f61e32c4 100644 (file)
@@ -266,6 +266,24 @@ SALOME::RequestSwitcher_ptr DataScopeServerBase::getRequestSwitcher()
   return SALOME::RequestSwitcher::_narrow(obj);
 }
 
+void DataScopeServerBase::takeANap(CORBA::Double napDurationInSec)
+{
+  if(napDurationInSec<0.)
+    throw Exception("DataScopeServerBase::takeANap : negative value !");
+#ifndef WIN32
+  struct timespec req,rem;
+  long nbSec((long)napDurationInSec);
+  double remainTime(napDurationInSec-(double)nbSec);
+  req.tv_sec=nbSec;
+  req.tv_nsec=(long)(remainTime*1000000.);
+  int ret(nanosleep(&req,&rem));
+  if(ret!=0)
+    throw Exception("DataScopeServerBase::takeANap : nap not finished as expected !");
+#else
+  throw Exception("DataScopeServerBase::takeANap : not implemented for Windows !");
+#endif
+}
+
 void DataScopeServerBase::initializePython(int argc, char *argv[])
 {
   Py_Initialize();
index e06ec8b22932132fa0eb7fd36f098bc9a7829d6e..eebdb37ec86c4007f839df8d780292b81c7bc538 100644 (file)
@@ -77,6 +77,7 @@ namespace SALOMESDS
     SALOME::ByteVec *fetchSerializedContent(const char *varName);
     SALOME::SeqOfByteVec *getAllKeysOfVarWithTypeDict(const char *varName);
     SALOME::RequestSwitcher_ptr getRequestSwitcher();
+    void takeANap(CORBA::Double napDurationInSec);
   public:
     ~DataScopeServerBase();
     BasicDataServer *retrieveVarInternal2(const std::string& varName);
index 96c6cf50632e37e68c464efd1fbc67fd2c78c474..d5ddd8447d08bce863937b4eeacd7ace86b702fa 100644 (file)
 #include "SALOMESDS_Exception.hxx"
 
 SALOMESDS::Exception::Exception(const std::string& reason)
+{
+  this->assign(reason.c_str());
+}
+
+SALOMESDS::Exception::Exception(const char *reason)
+{
+  this->assign(reason);
+}
+
+void SALOMESDS::Exception::assign(const char *reason)
 {
   SALOME::ExceptionStruct es;
   es.type=SALOME::INTERNAL_ERROR;
-  es.text=CORBA::string_dup(reason.c_str());
+  es.text=CORBA::string_dup(reason);
   es.lineNumber=0;
   (*this).details=es;
 }
-
-
index 28d910a1502f6e0df30ea8579b21859a6090b611..61b77f33a86f5438cbc061207a3aa57769275504 100644 (file)
@@ -34,6 +34,9 @@ namespace SALOMESDS
   {
   public:
     Exception(const std::string& reason);
+    Exception(const char *reason);
+  private:
+    void assign(const char *reason);
   };
 }
 
index bdbdc67616687d3a50a5c9ab49b0e0ac9a37a4ff..338953335d4c8d0bd8b8e7a4676f09c40cc372fd 100644 (file)
@@ -26,8 +26,11 @@ import unittest
 import cPickle
 import gc
 import time
+from datetime import datetime
 import multiprocessing as mp
 
+nbOfSecWait=1.
+
 def obj2Str(obj):
   return cPickle.dumps(obj,cPickle.HIGHEST_PROTOCOL)
 def str2Obj(strr):
@@ -54,7 +57,35 @@ def work(t):
       print out
       print err
     return proc.returncode
-
+  
+def func_test7(scopeName,l,l2,cv):
+    salome.salome_init()
+    varName="a"
+    zeValue={"ab":[4,5,6]}
+    dsm=salome.naming_service.Resolve("/DataServerManager")
+    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) # should be suspended nbOfSecWait s by main process
+    assert(not isCreated)
+    l.release() # tell manager that I'm ready
+    l2.acquire() # wait for manager to start micro-test1
+    ######### micro-test1 - check that all requests are suspended
+    s=datetime.now()
+    t0=dss.createRdWrVarTransac(varName,obj2Str(zeValue))
+    s=(datetime.now()-s).total_seconds()
+    assert(s>=0.99*nbOfSecWait and s<nbOfSecWait*1.01) # expect to wait nearly nbOfSecWait seconds
+    dss.atomicApply([t0])
+    ######### end of micro-test1
+    ######### micro-test2 - after activeRequests everything work well
+    s=datetime.now()
+    st=dss.fetchSerializedContent(varName)
+    assert(str2Obj(st)==zeValue)
+    s=(datetime.now()-s).total_seconds()
+    assert(s>=0. and s<0.05) # expect to be not locked
+    ######### end of micro-test2
+    with cv:
+      cv.notify_all()
+    dss.takeANap(nbOfSecWait) # emulate a DataServer occupation
+    pass
+  
 class SalomeSDSTest(unittest.TestCase):
   
   def testList1(self):
@@ -309,6 +340,42 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
     pass
 
+  def testLockToDump(self):
+    """ Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called.
+    Warning this method expects a not overloaded machine to be run because test is based on ellapse time.
+    """
+    scopeName="Scope1"
+    dsm=salome.naming_service.Resolve("/DataServerManager")
+    dsm.cleanScopesInNS()
+    if scopeName in dsm.listScopes():
+        dsm.removeDataScope(scopeName)
+    # l is for main process sync. to be sure to launch test when sub process is ready
+    # l2 lock is for sub process sync.
+    l=mp.Lock(); l2=mp.Lock()
+    l.acquire() ; l2.acquire()
+    cv=mp.Condition(mp.Lock())
+    dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
+    #assert(isCreated)
+    p=mp.Process(target=func_test7,args=(scopeName,l,l2,cv))
+    p.start()
+    l.acquire()
+    rs=dss.getRequestSwitcher() ; rs.holdRequests() # The aim of the test
+    l2.release() # tell slave process that it's ready for micro-test1
+    time.sleep(nbOfSecWait)
+    rs.activeRequests() # The aim of the test
+    ######### micro-test3 - check that holdRequests is able to wait for a non finished job
+    with cv:
+      cv.wait()
+      s=datetime.now()
+      time.sleep(0.01) # let main proc the priority
+      rs.holdRequests() # the aim of the test is here. main process is occupied 1s -> holdRequests is Expected to wait
+      s=(datetime.now()-s).total_seconds()
+      rs.activeRequests()
+      assert(s>=0.99*nbOfSecWait and s<nbOfSecWait*1.01) # expect to be not locked
+    # finishing
+    p.join()
+    pass
+
   def setUp(self):
     salome.salome_init()
     pass