Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Warren <bmw@users.noreply.github.com>2022-05-07 06:31:59 +0300
committerGitHub <noreply@github.com>2022-05-07 06:31:59 +0300
commit7dd1e814fb99770ac01e31db3855f483466dbcbb (patch)
tree002ed2ac3b8578a5e648e1cf540a0e253a890d4d
parent2017669544b1d296f10339321f5f66b6b5f158bf (diff)
Ignore parallel coverage files (#9293)
* ignore parallel coverage files * Properly shutdown & close HTTP server
-rw-r--r--.gitignore1
-rw-r--r--certbot-ci/certbot_integration_tests/utils/misc.py41
2 files changed, 15 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 285e68a42..d87bacc91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,7 @@ poetry.lock
# coverage
.coverage
+.coverage.*
/htmlcov/
/.vagrant
diff --git a/certbot-ci/certbot_integration_tests/utils/misc.py b/certbot-ci/certbot_integration_tests/utils/misc.py
index a36b348e0..a491ce9ba 100644
--- a/certbot-ci/certbot_integration_tests/utils/misc.py
+++ b/certbot-ci/certbot_integration_tests/utils/misc.py
@@ -4,8 +4,8 @@ or outside during setup/teardown of the integration tests environment.
"""
import contextlib
import errno
+import functools
import http.server as SimpleHTTPServer
-import multiprocessing
import os
import re
import shutil
@@ -13,6 +13,7 @@ import socketserver
import stat
import sys
import tempfile
+import threading
import time
import warnings
from typing import Generator
@@ -80,10 +81,6 @@ class GracefulTCPServer(socketserver.TCPServer):
allow_reuse_address = True
-def _run_server(port: int) -> None:
- GracefulTCPServer(('', port), SimpleHTTPServer.SimpleHTTPRequestHandler).serve_forever()
-
-
@contextlib.contextmanager
def create_http_server(port: int) -> Generator[str, None, None]:
"""
@@ -93,30 +90,20 @@ def create_http_server(port: int) -> Generator[str, None, None]:
:param int port: the TCP port to use
:return str: the temporary webroot attached to this server
"""
- current_cwd = os.getcwd()
- webroot = tempfile.mkdtemp()
-
- process = multiprocessing.Process(target=_run_server, args=(port,))
-
- try:
- # SimpleHTTPServer is designed to serve files from the current working directory at the
- # time it starts. So we temporarily change the cwd to our crafted webroot before launch.
- try:
- os.chdir(webroot)
- process.start()
- finally:
- os.chdir(current_cwd)
-
- check_until_timeout('http://localhost:{0}/'.format(port))
-
- yield webroot
- finally:
+ with tempfile.TemporaryDirectory() as webroot:
+ # Setting the directory argument of SimpleHTTPRequestHandler causes
+ # files to be served from that directory.
+ handler = functools.partial(SimpleHTTPServer.SimpleHTTPRequestHandler, directory=webroot)
+ server = GracefulTCPServer(('', port), handler)
+ thread = threading.Thread(target=server.serve_forever)
+ thread.start()
try:
- if process.is_alive():
- process.terminate()
- process.join() # Block until process is effectively terminated
+ check_until_timeout('http://localhost:{0}/'.format(port))
+ yield webroot
finally:
- shutil.rmtree(webroot)
+ server.shutdown()
+ thread.join()
+ server.server_close()
def list_renewal_hooks_dirs(config_dir: str) -> List[str]: