2 # Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from PortManager import getPort, releasePort, stopServer
23 import multiprocessing
26 def port_reservation(prefered=None, test=None, expected=None):
28 port = getPort(prefered)
31 print "port = %s"%port
34 print "expected = %s"%expected
35 test.assertTrue(port == expected)
38 class TestMinimalExample(unittest.TestCase):
40 def tearDownClass(cls):
42 stopServer() # no effect
44 def testSequential(self):
45 print "BEGIN testSequential"
47 multiprocessing.Process(target=port_reservation)
57 # Try to get specific port number
59 p = multiprocessing.Process(target=port_reservation, args=(2872, self,expected,))
63 # Try to get specific port number
64 p = multiprocessing.Process(target=port_reservation, args=(2812, self,))
69 p = multiprocessing.Process(target=releasePort, args=(2812,))
73 # Try to get specific port number
75 p = multiprocessing.Process(target=port_reservation, args=(2812, self,expected,))
79 print "END testSequential"
81 def testConcurrent(self):
82 print "BEGIN testConcurrent"
84 multiprocessing.Process(target=port_reservation)
88 # Try to get specific port number
89 p = multiprocessing.Process(target=port_reservation, args=(2852,))
92 # Try to get specific port number
93 p = multiprocessing.Process(target=port_reservation, args=(2812,))
97 p = multiprocessing.Process(target=releasePort, args=(2812,))
100 # Try to get specific port number
101 p = multiprocessing.Process(target=port_reservation, args=(2812,))
110 print "END testConcurrent"