Ejemplo n.º 1
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources: Set = set()

        from acme.standalone import HTTP01Server
        self.server = HTTP01Server(('', 0), resources=self.resources)

        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()
Ejemplo n.º 2
0
    def test_timely_shutdown(self):
        from acme.standalone import HTTP01Server
        server = HTTP01Server(('', 0), resources=set(), timeout=0.05)
        server_thread = threading.Thread(target=server.serve_forever)
        server_thread.start()

        client = socket.socket()
        client.connect(('localhost', server.socket.getsockname()[1]))

        stop_thread = threading.Thread(target=server.shutdown)
        stop_thread.start()
        server_thread.join(5.)

        is_hung = server_thread.is_alive()
        try:
            client.shutdown(socket.SHUT_RDWR)
        except:  # pragma: no cover, pylint: disable=bare-except
            # may raise error because socket could already be closed
            pass

        self.assertFalse(is_hung, msg='Server shutdown should not be hung')