# Path: misc/client.py
# def readline(sock):
# def readexact(sock, size):
#     def __init__(self, sock):
#     def read_status_line(self):
#     def read_headers(self):
#     def encoding(self):
#     def read_body(self):
#     def json(self):
#     def __init__(self, addr):
#     def maybe_connect(self):
#     def putline(self, line=None):
#     def putclose(self, data):
#     def putrequest(self, method, path, query_string=None):
#     def request(self, method, path, query_string=None, headers=None,
#                 body=None):
#     def putheader(self, name, value):
#     def endheaders(self, body=None):
#     def getresponse(self):
#     def close(self):
# def chunked_encoder(data):
# class Response:
# class Connection:


import pytest
import subprocess
import time
import integration_tests.common
from misc import client

pytestmark = pytest.mark.needs_build


@pytest.fixture(scope='function')
def server():
    return integration_tests.common.start_server(
        'integration_tests/drain.py', stdout=subprocess.PIPE, path='.test')


@pytest.fixture(scope='function')
def server_terminate(server):
    def terminate():
        server.terminate()
        assert server.wait() == 0

        stdout = server.stdout.read()

        return [l.decode('utf-8').strip() for l in stdout.splitlines()]

    yield terminate

    server.terminate()


@pytest.fixture(scope='function')
def connect():
    connections = []

    def _connect():

# Path: misc/client.py
# def readline(sock):
# def readexact(sock, size):
#     def __init__(self, sock):
#     def read_status_line(self):
#     def read_headers(self):
#     def encoding(self):
#     def read_body(self):
#     def json(self):
#     def __init__(self, addr):
#     def maybe_connect(self):
#     def putline(self, line=None):
#     def putclose(self, data):
#     def putrequest(self, method, path, query_string=None):
#     def request(self, method, path, query_string=None, headers=None,
#                 body=None):
#     def putheader(self, name, value):
#     def endheaders(self, body=None):
#     def getresponse(self):
#     def close(self):
# def chunked_encoder(data):
# class Response:
# class Connection:


# Path: integration_tests/test_drain.py
import pytest
import subprocess
import time
import integration_tests.common
from misc import client


pytestmark = pytest.mark.needs_build


@pytest.fixture(scope='function')
def server():
    return integration_tests.common.start_server(
        'integration_tests/drain.py', stdout=subprocess.PIPE, path='.test')


@pytest.fixture(scope='function')
def server_terminate(server):
    def terminate():
        server.terminate()
        assert server.wait() == 0

        stdout = server.stdout.read()

        return [l.decode('utf-8').strip() for l in stdout.splitlines()]

    yield terminate

    server.terminate()


@pytest.fixture(scope='function')
def connect():
    connections = []

    def _connect():

        conn = client.Connection('localhost:8080')