]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMESDS/TestSalomeSDS.py
Salome HOME
updated copyright message
[modules/kernel.git] / src / SALOMESDS / TestSalomeSDS.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay
21
22 import SalomeSDSClt
23 import SALOME
24 import salome
25 import unittest
26 import pickle
27 import gc
28 import time
29 from datetime import datetime
30 import multiprocessing as mp
31
32 nbOfSecWait=1.
33
34 def obj2Str(obj):
35   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
36 def str2Obj(strr):
37   return pickle.loads(strr)
38 def generateKey(varName,scopeName):
39   dsm=salome.naming_service.Resolve("/DataServerManager")
40   dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
41   assert(not isCreated)
42   t=dss.addKeyValueInVarHard(varName,obj2Str("ef"),obj2Str([11,14,100]))
43   time.sleep(3)
44   dss.atomicApply([t])
45 def work(t):
46   IORNS,i,varName,scopeName=t
47   if i==0:
48     generateKey(varName,scopeName)
49     return 0
50   else:
51     import TestSalomeSDSHelper0
52     import os,subprocess
53     fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py"
54     proc = subprocess.Popen(["python3", fname, IORNS], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55     out,err=proc.communicate()
56     if proc.returncode!=0:
57       print("-------------- work -----------")
58       print(out)
59       print(err)
60       print("~~~~~~~~~~~~~~ work ~~~~~~~~~~~")
61     return proc.returncode
62   
63 def func_test7(scopeName,cv,cv2,cv3,sharedNum):
64     salome.salome_init()
65     varName="a"
66     zeValue={"ab":[4,5,6]}
67     dsm=salome.naming_service.Resolve("/DataServerManager")
68     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName) # should be suspended nbOfSecWait s by main process
69     assert(not isCreated)
70     ######### micro-test1 - check that all requests are suspended
71     ######## Barrier
72     with cv2:
73       cv2.notify_all()
74       sharedNum.value=True
75     with cv3:
76       cv3.wait()
77     ####### End Barrier
78     s=datetime.now()
79     t0=dss.createRdWrVarTransac(varName,obj2Str(zeValue))
80     dss.atomicApply([t0])
81     s=(datetime.now()-s).total_seconds()
82     assert(s>=0.99*nbOfSecWait and s<nbOfSecWait*1.01) # expect to wait nearly nbOfSecWait seconds
83     ######### end of micro-test1
84     ######### micro-test2 - after activeRequests everything work well
85     s=datetime.now()
86     st=dss.fetchSerializedContent(varName)
87     assert(str2Obj(st)==zeValue)
88     s=(datetime.now()-s).total_seconds()
89     assert(s>=0. and s<0.05) # expect to be not locked
90     ######### end of micro-test2
91     with cv:
92       cv.notify_all()
93     dss.takeANap(nbOfSecWait) # emulate a DataServer occupation
94     pass
95   
96 class SalomeSDSTest(unittest.TestCase):
97   
98   def testList1(self):
99     scopeName = "Scope0"
100     a=SalomeSDSClt.CreateRdExtGlobalVar([],"a",scopeName)
101     self.assertEqual(a.local_copy(),[])
102     a.append(5)
103     self.assertEqual(a.local_copy(),[5])
104     self.assertRaises(SALOME.SALOME_Exception,a.__delitem__,0)
105     a.append(["rt"])
106     self.assertEqual(a.local_copy(),[5,["rt"]])
107     a[1].append(8)
108     self.assertEqual(a.local_copy(),[5,["rt",8]])
109     a.extend(a)
110     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8]])
111     a.extend(a[3:])
112     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8]])
113     a[4].append(7)
114     self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]])
115     a.ptr().getMyDataScopeServer().deleteVar("a")
116     del a
117     import gc
118     gc.collect(0)
119     salome.dsm.removeDataScope(scopeName)
120     pass
121   
122   def testDict1(self):
123     scopeName = "Scope0"
124     a=SalomeSDSClt.CreateRdExtGlobalVar({},"a",scopeName)
125     a["ab"]=4
126     self.assertEqual(a.local_copy(),{"ab":4})
127     a["cd"]=[5]
128     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
129     a["cd"].append(77)
130     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
131     a.__setitem__("ef",["a","bb"])
132     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
133     self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb"])
134     self.assertRaises(SALOME.SALOME_Exception,a.__setitem__,"ef",["a","bb","ccc"])
135     a["ef"].append("ccc")
136     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
137     a["gh"]=a
138     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
139     a["gh"]["cd"].append(99) ; a["cd"].append(88)
140     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
141     a.ptr().getMyDataScopeServer().deleteVar("a")
142     del a
143     import gc
144     gc.collect(0)
145     salome.dsm.removeDataScope(scopeName)
146     pass
147
148   def testReadOnly1(self):
149     scopeName = "Scope0"
150     #
151     a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a",scopeName)
152     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
153     self.assertRaises(Exception,a.__getitem__,"ab")
154     a.ptr().getMyDataScopeServer().deleteVar("a")
155     del a
156     import gc
157     gc.collect(0)
158     #
159     salome.dsm.removeDataScope(scopeName)
160
161   def testTransaction1(self):
162     scopeName="Scope1"
163     varName="a"
164     dsm=salome.naming_service.Resolve("/DataServerManager")
165     dsm.cleanScopesInNS()
166     if scopeName in dsm.listScopes():
167       dsm.removeDataScope(scopeName)
168     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
169     self.assertTrue(isCreated)
170     #
171     t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
172     dss.atomicApply([t0])
173     #
174     self.assertEqual(dss.getAccessOfVar(varName),"RdWr")
175     #
176     t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
177     dss.atomicApply([t1])
178     #
179     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
180     wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
181     wk.waitFor()
182     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
183     #
184     nbProc=8
185     pool=mp.Pool(processes=nbProc)
186     from NamingService import NamingService
187     asyncResult=pool.map_async(work,[(NamingService.IOROfNS(),i,varName,scopeName) for i in range(nbProc)])
188     print("asyncResult=", asyncResult)
189     self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here !
190     dsm.removeDataScope(scopeName)
191
192   def testTransaction2(self):
193     scopeName="Scope1"
194     varName="a"
195     dsm=salome.naming_service.Resolve("/DataServerManager")
196     dsm.cleanScopesInNS()
197     if scopeName in dsm.listScopes():
198       dsm.removeDataScope(scopeName)
199     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
200     self.assertTrue(isCreated)
201     #
202     t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
203     dss.atomicApply([t0])
204     #
205     self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
206     #
207     self.assertRaises(SALOME.SALOME_Exception,dss.addKeyValueInVarErrorIfAlreadyExisting,varName,obj2Str("ab"),obj2Str([7,8,9,10]))#raises because ab is already a key !
208     t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
209     dss.atomicApply([t1])
210     #
211     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
212     wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
213     wk.waitFor()
214     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
215     dsm.removeDataScope(scopeName)
216
217   def testTransaction3(self):
218     scopeName="Scope1"
219     varName="a"
220     dsm=salome.naming_service.Resolve("/DataServerManager")
221     dsm.cleanScopesInNS()
222     if scopeName in dsm.listScopes():
223       dsm.removeDataScope(scopeName)
224     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
225     self.assertTrue(isCreated)
226     #
227     t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
228     dss.atomicApply([t0])
229     #
230     t1=dss.addKeyValueInVarErrorIfAlreadyExisting(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
231     dss.atomicApply([t1])
232     #
233     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
234     #
235     t2=dss.removeKeyInVarErrorIfNotAlreadyExisting(varName,obj2Str("ab"))
236     dss.atomicApply([t2])
237     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]})
238     dsm.removeDataScope(scopeName)
239
240   def testTransaction4(self):
241     scopeName="Scope1"
242     varName="a"
243     dsm=salome.naming_service.Resolve("/DataServerManager")
244     dsm.cleanScopesInNS()
245     if scopeName in dsm.listScopes():
246       dsm.removeDataScope(scopeName)
247     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
248     self.assertTrue(isCreated)
249     #
250     t0=dss.createRdWrVarTransac(varName,obj2Str({"ab":[4,5,6]}))
251     dss.atomicApply([t0])
252     #
253     t1=dss.addKeyValueInVarHard(varName,obj2Str("cd"),obj2Str([7,8,9,10]))
254     dss.atomicApply([t1])
255     #
256     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
257     wk,t2=dss.waitForKeyInVarAndKillIt(varName,obj2Str("cd"))
258     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
259     wk.waitFor()
260     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
261     dss.atomicApply([t2])
262     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})
263     dsm.removeDataScope(scopeName)
264
265   def testTransaction5(self):
266     """ Like testTransaction2 but without transactions. """
267     scopeName="Scope1"
268     varName="a"
269     dsm=salome.naming_service.Resolve("/DataServerManager")
270     dsm.cleanScopesInNS()
271     if scopeName in dsm.listScopes():
272       dsm.removeDataScope(scopeName)
273     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
274     self.assertTrue(isCreated)
275     #
276     t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
277     dss.atomicApply([t0])
278     #
279     self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
280     t1=dss.addMultiKeyValueSession(varName)
281     self.assertEqual(dss.getAccessOfVar(varName),"RdExtInit")
282     self.assertRaises(SALOME.SALOME_Exception,t1.addKeyValueInVarErrorIfAlreadyExistingNow,obj2Str("ab"),obj2Str([7,8,9,10]))#raises because ab is already a key !
283     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})
284     wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
285     t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10]))
286     wk.waitFor()
287     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
288     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})# it is not a bug ! commit of t1 not done !
289     dss.atomicApply([t1])
290     self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
291     #
292     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
293     wk=dss.waitForKeyInVar(varName,obj2Str("cd"))
294     wk.waitFor()
295     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
296     keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)]
297     self.assertEqual(set(keys),set(['ab','cd']))
298     dsm.removeDataScope(scopeName)
299
300   def testTransaction6(self):
301     """ Test to test RdWr global vars with transaction"""
302     scopeName="Scope1"
303     varName="a"
304     dsm=salome.naming_service.Resolve("/DataServerManager")
305     dsm.cleanScopesInNS()
306     if scopeName in dsm.listScopes():
307       dsm.removeDataScope(scopeName)
308     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
309     self.assertTrue(isCreated)
310     #
311     t0=dss.createWorkingVarTransac(varName,obj2Str({}))
312     a=SalomeSDSClt.GetHandlerFromRef(t0.getVar())
313     self.assertEqual(dss.getAccessOfVar(varName),"RdWr")
314     # play
315     a["ab"]=4
316     self.assertEqual(a.local_copy(),{"ab":4})
317     a.assign({"ab":5})
318     self.assertEqual(a.local_copy(),{"ab":5})
319     a.assign({"ab":4})
320     a["cd"]=[5]
321     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5]})
322     a["cd"].append(77)
323     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]})
324     a.__setitem__("ef",["a","bb"])
325     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb"]})
326     a["ef"].append("ccc")
327     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]})
328     a["gh"]=a
329     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77],"ef":["a","bb","ccc"]}})
330     a["gh"]["cd"].append(99) ; a["cd"].append(88)
331     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}})
332     # WARNING here not problem to overwrite
333     a["gh"]=7
334     self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7})
335     # end of play
336     self.assertTrue(isinstance(a,SalomeSDSClt.Dict))
337     self.assertTrue(isinstance(a,SalomeSDSClt.WrappedType))# important for EEM
338     # commit : RdWr->RdOnly
339     dss.atomicApply([t0])
340     #
341     self.assertEqual(dss.getAccessOfVar(varName),"RdOnly") # after atomicApply the var is readOnly. Impossible to change its value !
342     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":7})
343     dsm.cleanScopesInNS()
344     del a # very important kill Ref before removingDataScope...
345     if scopeName in dsm.listScopes():
346       dsm.removeDataScope(scopeName)
347     pass
348
349   def testTransaction7(self):
350     """Like testTransaction5 but after a recovery."""
351     scopeName="Scope1"
352     varName="a"
353     dsm=salome.naming_service.Resolve("/DataServerManager")
354     dsm.cleanScopesInNS()
355     if scopeName in dsm.listScopes():
356       dsm.removeDataScope(scopeName)
357     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
358     self.assertTrue(isCreated)
359     #
360     t0=dss.createRdExtInitVarTransac(varName,obj2Str({"ab":[4,5,6]}))
361     dss.atomicApply([t0])
362     #
363     self.assertEqual(dss.getAccessOfVar(varName),"RdExtInit")
364     t1=dss.addMultiKeyValueSession(varName)
365     self.assertEqual(dss.getAccessOfVar(varName),"RdExtInit")
366     t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10]))
367     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})# it is not a bug ! commit of t1 not done !
368     dss.atomicApply([t1])
369     self.assertEqual(dss.getAccessOfVar(varName),"RdExt")
370     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]})
371     dsm.removeDataScope(scopeName)
372     pass
373
374   def testTransaction8(self):
375     """ EDF 16833 and EDF17719 """
376     funcContent="""def comptchev(a,b):
377     return "d" not in a
378 """
379     scopeName="ScopePP"
380     dsm=salome.naming_service.Resolve("/DataServerManager")
381     dsm.cleanScopesInNS()
382     if scopeName in dsm.listScopes():
383         dsm.removeDataScope(scopeName)
384     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
385     self.assertTrue(isCreated)
386
387     value={"a":1,"b":2}
388     value2={'a':1,'c':3,'b':2}
389     value3={'a':1,'c':3,'b':2,'d':4}
390
391     varName="abc"
392     t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) # sha1 is the key used to compare the initial value
393     dss.atomicApply([t0])
394     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
395     t1=dss.addMultiKeyValueSession(varName)
396     t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
397     dss.atomicApply([t1])
398     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
399     t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) # func says OK this is the same (even if it is not the case) as original one -> OK
400     dss.atomicApply([t2])
401     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2) # value2 remains untouched
402     t3=dss.addMultiKeyValueSession(varName)
403     t3.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("d"),obj2Str(4))
404     dss.atomicApply([t3])
405     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3)
406     t4=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent)
407     self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t4]) # d is in dict pointed by var. Func returns false -> rejected
408     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3)
409     dsm.removeDataScope(scopeName)
410     pass
411   
412   def testTransaction9(self):
413     """ EDF 16833 and EDF17719 : use case 2. Trying to createRdExt during add key session"""
414     funcContent="""def comptchev(a,b):
415     return a==b
416 """
417     scopeName="ScopePP"
418     dsm=salome.naming_service.Resolve("/DataServerManager")
419     dsm.cleanScopesInNS()
420     if scopeName in dsm.listScopes():
421         dsm.removeDataScope(scopeName)
422     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
423     self.assertTrue(isCreated)
424
425     value={"a":1,"b":2}
426     value2={'a':1,'c':3,'b':2}
427
428     varName="abc"
429     t0=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent)
430     dss.atomicApply([t0])
431     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
432     t1=dss.addMultiKeyValueSession(varName)
433     t2=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent)
434     dss.atomicApply([t2])
435     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value)
436     t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3))
437     dss.atomicApply([t1])
438     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2)
439     dsm.removeDataScope(scopeName)
440     pass
441
442     
443   def testLockToDump(self):
444     """ Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called.
445     Warning this method expects a not overloaded machine to be run because test is based on ellapse time.
446     """
447     scopeName="Scope1"
448     varName="ab"
449     zeObj={"ab":[5,6]}
450     dsm=salome.naming_service.Resolve("/DataServerManager")
451     dsm.cleanScopesInNS()
452     if scopeName in dsm.listScopes():
453         dsm.removeDataScope(scopeName)
454     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
455     self.assertTrue(isCreated)
456     cv=mp.Condition(mp.Lock())
457     cv2=mp.Condition(mp.Lock()) # sharedNum & cv2 & cv3 for the barrier
458     cv3=mp.Condition(mp.Lock())
459     sharedNum=mp.Value('b',False)
460     p=mp.Process(target=func_test7,args=(scopeName,cv,cv2,cv3,sharedNum))
461     p.start()
462     #
463     dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
464     self.assertTrue(not isCreated)
465     t0=dss.createRdWrVarTransac(varName,obj2Str(zeObj))
466     dss.atomicApply([t0])
467     rs=dss.getRequestSwitcher()
468     self.assertTrue(not isCreated)
469     ######## Barrier
470     with cv2:
471       if not sharedNum.value:
472         cv2.wait()
473       sharedNum.value=False
474       pass
475     with cv3:
476       cv3.notify_all()
477     ####### End Barrier
478     rs.holdRequests() # The aim of the test
479     self.assertEqual(rs.listVars(),[varName]) # call whereas holdRequest is called
480     time.sleep(nbOfSecWait)
481     rs.activeRequests() # The aim of the test
482     ######### micro-test3 - check that holdRequests is able to wait for a non finished job
483     with cv:
484       cv.wait()
485       s=datetime.now()
486       time.sleep(0.01) # let main proc the priority
487       rs.holdRequests() # the aim of the test is here. main process is occupied 1s -> holdRequests is Expected to wait
488       s=(datetime.now()-s).total_seconds()
489       self.assertTrue(str2Obj(rs.fetchSerializedContent(varName))==zeObj) # call whereas holdRequest is called
490       rs.activeRequests()
491       self.assertTrue(s>=0.99*nbOfSecWait and s<nbOfSecWait*1.01) # expect to be not locked
492     # finishing
493     p.join()
494     dsm.removeDataScope(scopeName)
495     pass
496   
497   def testShutdownScopes(self):
498     """ Test shutdownScopes.
499     """
500     salome.salome_init()
501     dss, isCreated = salome.dsm.giveADataScopeTransactionCalled('scope0')
502     t0 = dss.createRdExtVarTransac('a', obj2Str({}))
503     dss.atomicApply([t0])
504     salome.dsm.shutdownScopes() # no exception expected
505     pass
506
507   pass
508
509 if __name__=="__main__":
510   with salome.SessionContextManager():
511     unittest.main()
512
513