running_instances.put(instance)
#
+def createInstances(nb):
+ running_instances = multiprocessing.Queue()
+ processes = [
+ multiprocessing.Process(target=new_instance, args=(running_instances,))
+ for i in range(nb)
+ ]
+ return running_instances, processes
+#
+
+def terminateInstances(running_instances):
+ import time
+ timeout = time.time() + 60 * 10 # the test duration is about 50 s, we reasonably assume a max duration of 10mn
+
+ while not running_instances.empty() and time.time() < timeout:
+ instance = running_instances.get()
+ print("Terminate instance running on port", instance.get_port())
+ instance.stop()
+#
+
+def session(args=None):
+ if args is None:
+ args = []
+ try:
+ import setenv
+ setenv.main(True)
+ import runSession
+ params, args = runSession.configureSession(args, exe="salome shell")
+ return runSession.runSession(params, args)
+ except SystemExit as e:
+ if str(e) != '0':
+ logging.error(e)
+ pass
+#
+
+def appli(args=None):
+ if args is None:
+ args = []
+ try:
+ sys.argv = ['runSalome', '-t']
+ import setenv
+ setenv.main(True, exeName="salome start")
+ import runSalome
+ runSalome.runSalome()
+ except SystemExit as e:
+ if str(e) != '0':
+ logging.error(e)
+ pass
+#
+
class TestConcurrentLaunch(unittest.TestCase):
- def __createInstances(self, nb):
- running_instances = multiprocessing.Queue()
- processes = [
- multiprocessing.Process(target=new_instance, args=(running_instances,))
- for i in range(nb)
- ]
- return running_instances, processes
- #
- def __terminateInstances(self, running_instances):
- import time
- timeout = time.time() + 60*10 # the test duration is about 50 s, we reasonably assume a max duration of 10mn
-
- while not running_instances.empty() and time.time() < timeout:
- instance = running_instances.get()
- print("Terminate instance running on port", instance.get_port())
- instance.stop()
- #
- def appli(self, args=None):
- if args is None:
- args = []
- try:
- sys.argv = ['runSalome', '-t']
- import setenv
- setenv.main(True, exeName="salome start")
- import runSalome
- runSalome.runSalome()
- except SystemExit as e:
- if str(e) != '0':
- logging.error(e)
- pass
- #
- def session(self, args=None):
- if args is None:
- args = []
- try:
- import setenv
- setenv.main(True)
- import runSession
- params, args = runSession.configureSession(args, exe="salome shell")
- return runSession.runSession(params, args)
- except SystemExit as e:
- if str(e) != '0':
- logging.error(e)
- pass
- #
def test01_SingleSession(self):
print("** Testing single session **")
- self.session(["hello.py"])
- #
+ session(["hello.py"])
+
def test02_MultiSession(self):
print("** Testing multi sessions **")
jobs = []
for i in range(9):
- p = multiprocessing.Process(target=self.session, args=(["hello.py"],))
+ p = multiprocessing.Process(target=session, args=(["hello.py"],))
jobs.append(p)
p.start()
for j in jobs:
j.join()
#
+
def test03_SingleAppli(self):
print("** Testing single appli **")
- running_instances, processes = self.__createInstances(1)
+ running_instances, processes = createInstances(1)
for p in processes:
p.start()
pass
p.join()
pass
- self.session(["hello.py"])
- self.__terminateInstances(running_instances)
+ session(["hello.py"])
+ terminateInstances(running_instances)
#
+
def test04_MultiAppli(self):
print("** Testing multi appli **")
- running_instances, processes = self.__createInstances(9)
+ running_instances, processes = createInstances(9)
for p in processes:
p.start()
pass
p.join()
pass
- self.session(["hello.py"])
- self.__terminateInstances(running_instances)
+ session(["hello.py"])
+ terminateInstances(running_instances)
#
#
import unittest
import logging
-def port_reservation(obtained_ports, preferred=None, test=None, expected=None):
+
+def port_reservation(obtained_ports, preferred=None, name = None, messages=None, expected=None):
from PortManager import getPort
if preferred:
port = getPort(preferred)
obtained_ports.put(port)
- if expected:
- test.assertTrue(port == expected, "used = %s, expected = %s"%(port, expected))
+ if expected and messages:
+ _name = name + " : " if name else ""
+ if port != expected:
+ messages.put(_name + "used port= %s, expected port = %s"%(port, expected))
+ else:
+ messages.put(_name + "OK")
#
+
class TestMinimalExample(unittest.TestCase):
+
def testSequential(self):
from PortManager import releasePort, getBusyPorts
print("\nBEGIN testSequential")
print("Busy ports", getBusyPorts())
obtained_ports = multiprocessing.Queue()
+ messages = multiprocessing.Queue()
processes = [
multiprocessing.Process(target=port_reservation, args=(obtained_ports,))
print("Busy ports", getBusyPorts())
# Try to get specific port number
- p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,))
+ p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, "testSequential 2872",
+ messages, 2872,))
p.start()
p.join()
# Try to get specific port number
- p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812, self,))
+ p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,))
p.start()
p.join()
# Try to get specific port number
- p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,))
+ p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, "testSequential 2899:1",
+ messages, 2899,))
p.start()
p.join()
p.join()
# Try to get specific port number
- p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,))
+ p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, "testSequential 2899:2",
+ messages, 2899,))
p.start()
p.join()
+ # Check results
+ while not messages.empty():
+ message = messages.get()
+ if "OK" not in message:
+ self.fail(message)
+
# Release ports
print("Busy ports", getBusyPorts())
while not obtained_ports.empty():
print("\nBEGIN testConcurrent")
print("Busy ports", getBusyPorts())
obtained_ports = multiprocessing.Queue()
+ messages = multiprocessing.Queue()
processes = [
multiprocessing.Process(target=port_reservation, args=(obtained_ports,))
]
# Try to get specific port number
- p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,))
+ p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, "testSequential 2872",
+ messages, 2872,))
processes.append(p)
# Try to get specific port number
for p in processes:
p.join()
+ # Check results
+ while not messages.empty():
+ message = messages.get()
+ if "OK" not in message:
+ self.fail(message)
+
# Release ports
print("Busy ports", getBusyPorts())
while not obtained_ports.empty():
SET(tname salome_test)
-SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash)
-ADD_TEST(${TEST_NAME} bash ${tname}.sh)
-SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)
+IF (WIN32)
+ SET(PY_EXEC $ENV{PYTHONBIN})
+ELSE()
+ SET(PY_EXEC python)
+ENDIF()
-SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell)
-ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh)
-SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)
+IF(NOT WIN32)
+ SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash)
+ ADD_TEST(${TEST_NAME} bash ${tname}.sh)
+ SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)
+
+ SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell)
+ ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh)
+ SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)
+ENDIF()
SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_py)
-ADD_TEST(${TEST_NAME} python ${tname}.py)
+ADD_TEST(${TEST_NAME} ${PY_EXEC} ${tname}.py)
SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)
SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_driver)
-ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py)
+ADD_TEST(${TEST_NAME} ${PY_EXEC} ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py)
SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)