mirror of
https://github.com/actix/actix-web.git
synced 2024-05-08 11:33:04 +00:00
Compare commits
9 commits
1d63419864
...
e9939684bf
Author | SHA1 | Date | |
---|---|---|---|
e9939684bf | |||
ba7fd048b6 | |||
d98938b125 | |||
5a5486b484 | |||
76b2b2734b | |||
243ddd71ed | |||
7a27ccffcb | |||
a5f8534573 | |||
d3911ec285 |
6
.github/workflows/ci-post-merge.yml
vendored
6
.github/workflows/ci-post-merge.yml
vendored
|
@ -45,7 +45,7 @@ jobs:
|
|||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack and cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: cargo-hack,cargo-ci-cache-clean
|
||||
|
||||
|
@ -88,7 +88,7 @@ jobs:
|
|||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
|
||||
- name: Install cargo-hack
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: cargo-hack
|
||||
|
||||
|
@ -109,7 +109,7 @@ jobs:
|
|||
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
|
||||
|
||||
- name: Install nextest
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: nextest
|
||||
|
||||
|
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -50,7 +50,7 @@ jobs:
|
|||
toolchain: ${{ matrix.version.version }}
|
||||
|
||||
- name: Install cargo-hack and cargo-ci-cache-clean
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: cargo-hack,cargo-ci-cache-clean
|
||||
|
||||
|
|
4
.github/workflows/coverage.yml
vendored
4
.github/workflows/coverage.yml
vendored
|
@ -23,7 +23,7 @@ jobs:
|
|||
components: llvm-tools-preview
|
||||
|
||||
- name: Install cargo-llvm-cov
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: cargo-llvm-cov
|
||||
|
||||
|
@ -31,7 +31,7 @@ jobs:
|
|||
run: cargo llvm-cov --workspace --all-features --codecov --output-path codecov.json
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v4.1.1
|
||||
uses: codecov/codecov-action@v4.3.0
|
||||
with:
|
||||
files: codecov.json
|
||||
fail_ci_if_error: true
|
||||
|
|
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
|
@ -82,7 +82,7 @@ jobs:
|
|||
toolchain: nightly-2023-08-25
|
||||
|
||||
- name: Install cargo-public-api
|
||||
uses: taiki-e/install-action@v2.32.0
|
||||
uses: taiki-e/install-action@v2.32.17
|
||||
with:
|
||||
tool: cargo-public-api
|
||||
|
||||
|
|
|
@ -52,6 +52,10 @@ async fn common_test_code(mut srv: actix_test::TestServer, frame_size: usize) {
|
|||
.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
|
||||
|
||||
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
|
||||
assert_eq!(true, nothing.is_ok());
|
||||
assert_eq!(true, nothing.unwrap().is_none());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
|
|
96
actix-web-actors/tests/test_ws_close.rs
Normal file
96
actix-web-actors/tests/test_ws_close.rs
Normal file
|
@ -0,0 +1,96 @@
|
|||
use actix::prelude::*;
|
||||
use actix_web::{web, App, HttpRequest};
|
||||
use actix_web_actors::ws;
|
||||
use futures_util::{SinkExt as _, StreamExt as _};
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
struct Ws {
|
||||
finished: Sender<()>,
|
||||
}
|
||||
|
||||
impl Actor for Ws {
|
||||
type Context = ws::WebsocketContext<Self>;
|
||||
}
|
||||
|
||||
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Ws {
|
||||
fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
|
||||
match msg {
|
||||
Ok(ws::Message::Close(reason)) => ctx.close(reason),
|
||||
_ => ctx.close(Some(ws::CloseCode::Normal.into())),
|
||||
}
|
||||
}
|
||||
|
||||
fn finished(&mut self, _ctx: &mut Self::Context) {
|
||||
_ = self.finished.try_send(()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn close_initiated_by_client() {
|
||||
let (tx, mut finished) = tokio::sync::mpsc::channel(1);
|
||||
let mut srv = actix_test::start(move || {
|
||||
let tx = tx.clone();
|
||||
App::new().service(web::resource("{anything:.*}").to(
|
||||
move |req: HttpRequest, stream: web::Payload| {
|
||||
let tx: Sender<()> = tx.clone();
|
||||
async move { ws::WsResponseBuilder::new(Ws { finished: tx }, &req, stream).start() }
|
||||
},
|
||||
))
|
||||
});
|
||||
|
||||
let mut framed = srv.ws().await.unwrap();
|
||||
|
||||
framed
|
||||
.send(ws::Message::Close(Some(ws::CloseCode::Normal.into())))
|
||||
.await
|
||||
.unwrap();
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
|
||||
|
||||
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
|
||||
assert_eq!(true, nothing.is_ok());
|
||||
assert_eq!(true, nothing.unwrap().is_none());
|
||||
|
||||
let finished =
|
||||
actix_rt::time::timeout(std::time::Duration::from_secs(1), finished.recv()).await;
|
||||
assert_eq!(true, finished.is_ok());
|
||||
assert_eq!(Some(()), finished.unwrap());
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn close_initiated_by_server() {
|
||||
let (tx, mut finished) = tokio::sync::mpsc::channel(1);
|
||||
let mut srv = actix_test::start(move || {
|
||||
let tx = tx.clone();
|
||||
App::new().service(web::resource("{anything:.*}").to(
|
||||
move |req: HttpRequest, stream: web::Payload| {
|
||||
let tx: Sender<()> = tx.clone();
|
||||
async move { ws::WsResponseBuilder::new(Ws { finished: tx }, &req, stream).start() }
|
||||
},
|
||||
))
|
||||
});
|
||||
|
||||
let mut framed = srv.ws().await.unwrap();
|
||||
|
||||
framed
|
||||
.send(ws::Message::Text("I'll initiate close by server".into()))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
|
||||
|
||||
framed
|
||||
.send(ws::Message::Close(Some(ws::CloseCode::Normal.into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
|
||||
assert_eq!(true, nothing.is_ok());
|
||||
assert_eq!(true, nothing.unwrap().is_none());
|
||||
|
||||
let finished =
|
||||
actix_rt::time::timeout(std::time::Duration::from_secs(1), finished.recv()).await;
|
||||
assert_eq!(true, finished.is_ok());
|
||||
assert_eq!(Some(()), finished.unwrap());
|
||||
}
|
|
@ -65,4 +65,8 @@ async fn test_simple() {
|
|||
|
||||
let item = framed.next().await.unwrap().unwrap();
|
||||
assert_eq!(item, ws::Frame::Close(Some(ws::CloseCode::Normal.into())));
|
||||
|
||||
let nothing = actix_rt::time::timeout(std::time::Duration::from_secs(1), framed.next()).await;
|
||||
assert_eq!(true, nothing.is_ok());
|
||||
assert_eq!(true, nothing.unwrap().is_none());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue