1 # Copyright (C) 2015-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 import multiprocessing
23 def new_instance(running_instances):
24 from salome_instance import SalomeInstance
25 instance = SalomeInstance.start()
26 print("Instance created and now running on port", instance.get_port())
27 running_instances.put(instance)
30 class TestLauncher(unittest.TestCase):
32 def __createInstances(self, nb):
33 running_instances = multiprocessing.Queue()
35 multiprocessing.Process(target=new_instance, args=(running_instances,))
38 return running_instances, processes
41 def __terminateInstances(self, running_instances):
42 while not running_instances.empty():
43 instance = running_instances.get()
44 print("Terminate instance running on port", instance.get_port())
48 def __connectToInstance(self, port):
52 return runConsole.connect(["-p", port, "-c", "exit()"]) # auto-logout
55 def testSequential(self):
56 running_instances, processes = self.__createInstances(3)
62 self.__terminateInstances(running_instances)
65 def testConcurrent(self):
66 running_instances, processes = self.__createInstances(5)
74 self.__terminateInstances(running_instances)
77 def testConnectInstance(self):
78 # Create some instances
79 running_instances, processes = self.__createInstances(5)
87 # move queued instances to a list
89 while not running_instances.empty():
90 all_instances.append(running_instances.get())
92 # Connect to one instance
94 port = all_instances[len(all_instances)//2].get_port()
95 print("Connect to instance running on port", port)
96 self.__connectToInstance(port)
98 # Connect to another instance
100 port = all_instances[len(all_instances)//4].get_port()
101 print("Connect to instance running on port", port)
102 self.__connectToInstance(port)
104 # Terminate instances
105 for instance in all_instances:
106 print("Terminate instance running on port", instance.get_port())
110 if __name__ == "__main__":