Beispiel #1
0
def test_unix(tmpdir, Poller):
    m = Manager() + Poller()

    sockpath = tmpdir.ensure("test.sock")
    filename = str(sockpath)

    server = Server() + UNIXServer(filename)
    client = Client() + UNIXClient()

    server.register(m)
    client.register(m)

    m.start()

    try:
        assert pytest.wait_for(server, "ready")
        assert pytest.wait_for(client, "ready")

        client.fire(connect(filename))
        assert pytest.wait_for(client, "connected")
        assert pytest.wait_for(server, "connected")
        assert pytest.wait_for(client, "data", b"Ready")

        client.fire(write(b"foo"))
        assert pytest.wait_for(server, "data", b"foo")

        client.fire(close())
        assert pytest.wait_for(client, "disconnected")
        assert pytest.wait_for(server, "disconnected")

        server.fire(close())
        assert pytest.wait_for(server, "closed")
    finally:
        m.stop()
        os.remove(filename)
Beispiel #2
0
def test_unix(tmpfile, Poller):
    m = Manager() + Poller()

    server = Server() + UNIXServer(tmpfile)
    client = Client() + UNIXClient()

    server.register(m)
    client.register(m)

    m.start()

    try:
        assert pytest.wait_for(server, "ready")
        assert pytest.wait_for(client, "ready")

        client.fire(connect(tmpfile))
        assert pytest.wait_for(client, "connected")
        assert pytest.wait_for(server, "connected")
        assert pytest.wait_for(client, "data", b"Ready")

        client.fire(write(b"foo"))
        assert pytest.wait_for(server, "data", b"foo")

        client.fire(close())
        assert pytest.wait_for(client, "disconnected")
        assert pytest.wait_for(server, "disconnected")

        server.fire(close())
        assert pytest.wait_for(server, "closed")
    finally:
        m.stop()
Beispiel #3
0
def test(manager, watcher, webapp, chunksize):
    echo = Echo().register(webapp)
    assert watcher.wait("registered", channel="wsserver")

    f = urlopen(webapp.server.http.base)
    s = f.read()
    assert s == b"Hello World!"

    watcher.clear()

    WebSocketsDispatcher("/websocket").register(webapp)
    assert watcher.wait("registered", channel="web")

    uri = "ws://{0:s}:{1:d}/websocket".format(
        webapp.server.host, webapp.server.port)

    WebSocketClient(uri).register(manager)
    client = Client().register(manager)
    assert watcher.wait("registered", channel="wsclient")
    assert watcher.wait("connected", channel="wsclient")

    assert watcher.wait("connect", channel="wsserver")
    assert len(echo.clients) == 1

    assert watcher.wait("read", channel="ws")
    assert client.response.startswith("Welcome")
    watcher.clear()

    client.fire(write("Hello!"), "ws")
    assert watcher.wait("read", channel="ws")
    assert client.response == "Received: Hello!"

    watcher.clear()

    client.fire(write("World!"), "ws")
    assert watcher.wait("read", channel="ws")
    assert client.response == "Received: World!"

    watcher.clear()

    data = "A" * (chunksize + 1)
    client.fire(write(data), "ws")
    assert watcher.wait("read", channel="ws")
    assert client.response == "Received: %s" % (data,)

    f = urlopen(webapp.server.http.base)
    s = f.read()
    assert s == b"Hello World!"

    assert len(echo.clients) == 1

    client.fire(close(), "ws")
    assert watcher.wait("disconnect", channel="wsserver")
    assert len(echo.clients) == 0

    client.unregister()
    assert watcher.wait("unregistered")
Beispiel #4
0
def test(manager, watcher, webapp):
    echo = Echo().register(webapp)
    assert watcher.wait("registered", channel="wsserver")

    f = urlopen(webapp.server.http.base)
    s = f.read()
    assert s == b"Hello World!"

    watcher.clear()

    WebSocketsDispatcher("/websocket").register(webapp)
    assert watcher.wait("registered", channel="web")

    uri = "ws://{0:s}:{1:d}/websocket".format(webapp.server.host,
                                              webapp.server.port)

    WebSocketClient(uri).register(manager)
    client = Client().register(manager)
    assert watcher.wait("registered", channel="wsclient")
    assert watcher.wait("connected", channel="wsclient")

    assert watcher.wait("connect", channel="wsserver")
    assert len(echo.clients) == 1

    assert watcher.wait("read", channel="ws")
    assert client.response.startswith("Welcome")
    watcher.clear()

    client.fire(write("Hello!"), "ws")
    assert watcher.wait("read", channel="ws")
    assert client.response == "Received: Hello!"

    for size in (BUFSIZE, BUFSIZE + 1, BUFSZIE * 2):
        data = "A" * (size + 1)
        client.fire(write(data), "ws")
        assert watcher.wait("read", channel="ws")
        assert client.response == "Received: %s" % (data, )

    f = urlopen(webapp.server.http.base)
    s = f.read()
    assert s == b"Hello World!"

    assert len(echo.clients) == 1

    client.fire(close(), "ws")
    assert watcher.wait("disconnect", channel="wsserver")
    assert len(echo.clients) == 0

    client.unregister()
    assert watcher.wait("unregistered")
Beispiel #5
0
 def close(self):
     self._clear_timer()
     if self._transport.connected:
         self.fire(close(), self._transport)
Beispiel #6
0
 def _on_response(self, response):
     self._response = response
     self._outstanding -= 1
     self._clear_timer()
     if response.headers.get("Connection") == "Close":
         self.fire(close(), self._transport)
Beispiel #7
0
    def finalizer():
        webapp.fire(close())
        assert watcher.wait("closed")

        webapp.unregister()
        assert watcher.wait("unregistered")
Beispiel #8
0
    def finalizer():
        webapp.fire(close())
        assert watcher.wait("closed")

        webapp.unregister()
        assert watcher.wait("unregistered")
Beispiel #9
0
 def finalizer():
     webapp.fire(close(), webapp.server)
     webapp.stop()
Beispiel #10
0
	def _do_cmd_quit(self):
		print("Exiting...")
		self.waiting = True
		self.fire(sockets.close())
Beispiel #11
0
 def close(self):
     self._clear_timer()
     if self._transport.connected:
         self.fire(close(), self._transport)
Beispiel #12
0
 def _on_response(self, response):
     self._response = response
     self._outstanding -= 1
     self._clear_timer()
     if response.headers.get("Connection") == "Close":
         self.fire(close(), self._transport)
Beispiel #13
0
 def finalizer():
     webapp.fire(close(), webapp.server)
     webapp.stop()