1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

actix 0.5.5, ws test

This commit is contained in:
Nikolay Kim 2018-03-19 13:12:36 -07:00
parent e7ec0f9fd7
commit 35ee5d36d8
5 changed files with 61 additions and 11 deletions

View File

@ -42,7 +42,7 @@ session = ["cookie/secure"]
brotli = ["brotli2"]
[dependencies]
actix = "^0.5.4"
actix = "^0.5.5"
base64 = "0.9"
bitflags = "1.0"

View File

@ -557,8 +557,7 @@ impl<S: 'static, H> ProcessResponse<S, H> {
Ok(result) => res = Some(result),
}
},
Frame::Drain(fut) =>
self.drain = Some(fut),
Frame::Drain(fut) => self.drain = Some(fut),
}
}
self.iostate = IOState::Actor(ctx);

View File

@ -241,7 +241,7 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
self.encoder.write(payload)?;
}
} else {
// might be response to EXCEPT
// could be response to EXCEPT header
self.buffer.extend_from_slice(payload.as_ref())
}
}

View File

@ -456,14 +456,12 @@ impl Stream for ClientReader {
Ok(Async::Ready(Some(frame))) => {
let (finished, opcode, payload) = frame.unpack();
// continuation is not supported
if !finished {
inner.closed = true;
return Err(ProtocolError::NoContinuation)
}
match opcode {
OpCode::Continue => unimplemented!(),
// continuation is not supported
OpCode::Continue => {
inner.closed = true;
return Err(ProtocolError::NoContinuation)
},
OpCode::Bad => {
inner.closed = true;
Err(ProtocolError::BadOpCode)

View File

@ -91,3 +91,56 @@ fn test_large_bin() {
assert_eq!(item, Some(ws::Message::Binary(Binary::from(data.clone()))));
}
}
struct Ws2 {
count: usize
}
impl Actor for Ws2 {
type Context = ws::WebsocketContext<Self>;
fn started(&mut self, ctx: &mut Self::Context) {
self.send(ctx);
}
}
impl Ws2 {
fn send(&mut self, ctx: &mut ws::WebsocketContext<Self>) {
ctx.text("0".repeat(65_536));
ctx.drain().and_then(|_, act, ctx| {
act.count += 1;
if act.count != 100 {
act.send(ctx);
}
actix::fut::ok(())
}).wait(ctx);
}
}
impl StreamHandler<ws::Message, ws::ProtocolError> for Ws2 {
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
match msg {
ws::Message::Ping(msg) => ctx.pong(&msg),
ws::Message::Text(text) => ctx.text(text),
ws::Message::Binary(bin) => ctx.binary(bin),
ws::Message::Close(reason) => ctx.close(reason, ""),
_ => (),
}
}
}
#[test]
fn test_server_send_text() {
let data = Some(ws::Message::Text("0".repeat(65_536)));
let mut srv = test::TestServer::new(
|app| app.handler(|req| ws::start(req, Ws2{count:0})));
let (mut reader, _writer) = srv.ws().unwrap();
for _ in 0..100 {
let (item, r) = srv.execute(reader.into_future()).unwrap();
reader = r;
assert_eq!(item, data);
}
}