'Test socket activation'

@skipIf((not has_preactivated_support), u'pre_activated_socket    not    available')
def test_socket_activation(self):

    os.closerange(3, 4)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
    s.bind((u'localhost', 0))
    port = s.getsockname()[1]
    self.ae(s.fileno(), 3)
    os.environ[u'LISTEN_PID'] = str(os.getpid())
    os.environ[u'LISTEN_FDS'] = u'1'
    with TestServer((lambda data: (data.path[0] + data.read())), allow_socket_preallocation=True) as server:
        conn = server.connect()
        conn.request(u'GET', u'/test', u'body')
        r = conn.getresponse()
        self.ae(r.status, httplib.OK)
        self.ae(r.read(), 'testbody')
        self.ae(server.loop.bound_address[1], port)
