def test_transport(self):
        url = base_url + '/000/' + str(uuid.uuid4())
        r = POST_async(url + '/xhr_streaming')
        self.assertEqual(r.status, 200)
        self.assertEqual(r['Content-Type'],
                         'application/javascript; charset=UTF-8')
        self.verify_cookie(r)
        self.verify_cors(r)

        # The transport must first send 2KiB of `h` bytes as prelude.
        self.assertEqual(r.read(), 'h' *  2048 + '\n')

        self.assertEqual(r.read(), 'o\n')

        r1 = POST(url + '/xhr_send', body='["x"]')
        self.assertFalse(r1.body)
        self.assertEqual(r1.status, 204)

        self.assertEqual(r.read(), 'a["x"]\n')
        r.close()
    def test_basic(self):
        t0 = time.time()
        r = POST_async(base_url + '/chunking_test')
        self.assertEqual(r.status, 200)
        self.assertEqual(r['content-type'],
                         'application/javascript; charset=UTF-8')
        self.verify_no_cookie(r)
        self.verify_cors(r)

        # In first chunk the server must send a 'h' frame:
        self.assertEqual(r.read(), 'h\n')
        # As second chunk the server must send 2KiB prelude.
        self.assertEqual(r.read(), ' ' * 2048 + 'h\n')
        # Later the server must send a `h` byte.
        self.assertEqual(r.read(), 'h\n')
        # In third chunk the server must send a `h` byte.
        self.assertEqual(r.read(), 'h\n')

        # At least 30 ms must have passed since the request.
        t1 = time.time()
        self.assertGreater((t1-t0) * 1000., 30.)
        r.close()
    def test_closeSession_another_connection(self):
        # When server is closing session, it should unlink current
        # request. That means, if a new request appears, it should
        # receive an application close message rather than "Another
        # connection still open" message.
        url = close_base_url + '/000/' + str(uuid.uuid4())
        r1 = POST_async(url + '/xhr_streaming')

        r1.read() # prelude
        self.assertEqual(r1.read(), 'o\n')
        self.assertEqual(r1.read(), 'c[3000,"Go away!"]\n')

        r2 = POST_async(url + '/xhr_streaming')
        r2.read() # prelude
        self.assertEqual(r2.read(), 'c[3000,"Go away!"]\n')

        ''' TODO: should request be automatically closed after close?