Commit 98b7b05c authored by Jérome Perrin's avatar Jérome Perrin

software/erp5/test: fix ResourceWarning on python3

 - use the requests.Session in a context manager so that resources are
properly closed.
 - close the stdout of caucase process we want to keep silent
parent 8a72ec0b
...@@ -110,6 +110,7 @@ class CaucaseService(ManagedResource): ...@@ -110,6 +110,7 @@ class CaucaseService(ManagedResource):
'--netloc', backend_caucased_netloc, '--netloc', backend_caucased_netloc,
'--service-auto-approve-count', '1', '--service-auto-approve-count', '1',
], ],
# capture subprocess output not to pollute test's own stdout
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
) )
...@@ -127,6 +128,7 @@ class CaucaseService(ManagedResource): ...@@ -127,6 +128,7 @@ class CaucaseService(ManagedResource):
# type: () -> None # type: () -> None
self._caucased_process.terminate() self._caucased_process.terminate()
self._caucased_process.wait() self._caucased_process.wait()
self._caucased_process.stdout.close()
shutil.rmtree(self.directory) shutil.rmtree(self.directory)
...@@ -525,7 +527,7 @@ class TestHTTP(BalancerTestCase): ...@@ -525,7 +527,7 @@ class TestHTTP(BalancerTestCase):
def test_keep_alive(self): def test_keep_alive(self):
# type: () -> None # type: () -> None
# when doing two requests, connection is established only once # when doing two requests, connection is established only once
session = requests.Session() with requests.Session() as session:
session.verify = False session.verify = False
# do a first request, which establish a first connection # do a first request, which establish a first connection
...@@ -539,6 +541,7 @@ class TestHTTP(BalancerTestCase): ...@@ -539,6 +541,7 @@ class TestHTTP(BalancerTestCase):
new_conn.assert_not_called() new_conn.assert_not_called()
parsed_url = six.moves.urllib.parse.urlparse(self.default_balancer_url) parsed_url = six.moves.urllib.parse.urlparse(self.default_balancer_url)
# check that we have an open file for the ip connection # check that we have an open file for the ip connection
self.assertTrue([ self.assertTrue([
c for c in psutil.Process(os.getpid()).connections() c for c in psutil.Process(os.getpid()).connections()
......
...@@ -64,7 +64,7 @@ class TestPublishedURLIsReachableMixin(object): ...@@ -64,7 +64,7 @@ class TestPublishedURLIsReachableMixin(object):
# erp5 site is not created, with 500 when mysql is not yet reachable, so we # erp5 site is not created, with 500 when mysql is not yet reachable, so we
# configure this requests session to retry. # configure this requests session to retry.
# XXX we should probably add a promise instead # XXX we should probably add a promise instead
session = requests.Session() with requests.Session() as session:
session.mount( session.mount(
base_url, base_url,
requests.adapters.HTTPAdapter( requests.adapters.HTTPAdapter(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment